match(regexp) deciphering

B

brad

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(/^(.+?)(?:\?(?:(.*?)@)?(.+))?$/)
 
T

Thomas 'PointedEars' Lahn

brad said:
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:RegExp>
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:String: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
 
T

Thomas 'PointedEars' Lahn

Thomas said:
brad said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top