match(regexp) deciphering

Discussion in 'Javascript' started by brad, Feb 28, 2006.

  1. brad

    brad Guest

    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(/^(.+?)(?:\?(?:(.*?)@)?(.+))?$/)
     
    brad, Feb 28, 2006
    #1
    1. Advertising

  2. 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: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
     
    Thomas 'PointedEars' Lahn, Feb 28, 2006
    #2
    1. Advertising

  3. 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
     
    Thomas 'PointedEars' Lahn, Feb 28, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philip S

    Deciphering ISO C (Chap 6.3.2.3 - Pointers)

    Philip S, Nov 10, 2003, in forum: C Programming
    Replies:
    2
    Views:
    430
    Keith Thompson
    Nov 10, 2003
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    506
    Mikel Lindsaar
    Mar 31, 2008
  3. Old Echo
    Replies:
    1
    Views:
    187
    Adam Shelly
    Sep 4, 2008
  4. Joao Silva
    Replies:
    16
    Views:
    377
    7stud --
    Aug 21, 2009
  5. Uldis  Bojars
    Replies:
    2
    Views:
    196
    Janwillem Borleffs
    Dec 17, 2006
Loading...

Share This Page