Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > match(regexp) deciphering

Reply
Thread Tools

match(regexp) deciphering

 
 
brad
Guest
Posts: n/a
 
      02-28-2006
Hello all, I'm new to javascript--not too new to a few other
programming languages--and I need your help deciphering the Regexp in
the following string. Regular expresions are hard enough in Python, and
since I am new to javascript they are even harder. Well here's the
string, thanks for any and all help I receive.


document.URL.match(/^(.+?)(?:\?(?.*?)@)?(.+))?$/)

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-28-2006
brad wrote:

> Hello all, I'm new to javascript--not too new to a few other
> programming languages--and I need your help deciphering the Regexp in
> the following string. Regular expresions are hard enough in Python, and
> since I am new to javascript they are even harder. Well here's the
> string, thanks for any and all help I receive.
>
> document.URL.match(/^(.+?)(?:\?(?.*?)@)?(.+))?$/)


Match
the beginning of input (`^')
followed by
one or more occurrences (`+') of any character except newline (`.'),
shortest match wins (`?')
followed by none or one occurrence (`?') of
the literal character `?' (`\?')
followed by zero or one occurrence (`?') of
zero or more occurrences (`*') of any character except newline (`.'),
shortest match wins (`?')
followed by
`@'
where the match of the subexpression is not captured (`(?:...)'),
where the match of the subexpression is not captured (`(?:...)'),
followed by
one or more occurrences of any character except newline
followed by
the end of input
in the value of `document.URL' and return a reference to an Array-like
object (one including numerically iterable properties) with each match
of a captured paranthesed subexpression being available as property of
that object with numerical name, starting with "0" as the property name
for the first captured match.

<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:RegEx p>
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Strin g:match>

(Once you have learned how to read and interpret Regular Expressions,
they are no mystery to you anymore, no matter the used flavour. See
also <URL:http://oreilly.com/catalog/regex/>; the sample chapters
sufficed for me to date.)

Note that non-capturing parantheses are not backwards compatible. It is
better not to use them here, and to use the backreference with greater
index instead.

The code does not make sense because it appears to check for some form of
URI-inline authentication while it also indicates it runs in a client-side,
HTML environment (`URL' is a property of HTMLDocument DOM host objects).
However, this code must not apply to a valid http(s) URI; usernames and
passwords are not allowed in them and user agents that support them there
anyway are broken. Meaning that this is a security leak there that will be
fixed soon or is already fixed in the next version. So this is an approach
that is not at all reliable.


PointedEars
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-28-2006
Thomas 'PointedEars' Lahn wrote:

> brad wrote:
>> Hello all, I'm new to javascript--not too new to a few other
>> programming languages--and I need your help deciphering the Regexp in
>> the following string. Regular expresions are hard enough in Python, and
>> since I am new to javascript they are even harder. Well here's the
>> string, thanks for any and all help I receive.
>>
>> document.URL.match(/^(.+?)(?:\?(?.*?)@)?(.+))?$/)

>
> [...] and return a reference to an Array-like object (one including
> numerically iterable properties) with each match of a captured paranthesed
> subexpression being available as property of that object with numerical
> name, starting with "0" as the property name for the first captured match.


Sorry, that is nonsense. Should have been

.... starting with "0" as the property name for the match of the whole
expression, "1" for the captured match of the first paranthesed
subexpression (here: /.+?/) and so on.


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
deciphering trace info rodchar ASP .Net 2 08-18-2008 03:57 PM
Need help deciphering some code Cogito HTML 2 07-21-2007 07:04 AM
help deciphering registry error Opsimath Computer Support 6 11-28-2005 02:58 AM
stat.st_mode deciphering John C Programming 1 06-19-2004 01:22 PM
Deciphering ISO C (Chap 6.3.2.3 - Pointers) Philip S C Programming 2 11-10-2003 09:34 PM



Advertisments