regex bug (comments within regex not as robust)

Discussion in 'Perl Misc' started by kg.google@olympiakos.com, Oct 27, 2005.

  1. Guest

    Code:

    if
    (
    $x =~
    /
    \d+ # this slash / generates an error
    /x
    )
    {
    }

    version:
    activestate perl 5.8.7

    regards,
    Kiriakos Georgiou
     
    , Oct 27, 2005
    #1
    1. Advertising

  2. Dave Guest

    <> wrote in message
    news:...
    > Code:
    >
    > if
    > (
    > $x =~
    > /
    > \d+ # this slash / generates an error
    > /x
    > )
    > {
    > }
    >
    > version:
    > activestate perl 5.8.7
    >
    > regards,
    > Kiriakos Georgiou
    >


    This is not a bug. The compiler doesn't see the /x switch until it has found
    the limits of the regex, so the / in the comment gives it a false ending
    (see the footnote on p148 of the camel book). If you want to use / in your
    comments use {} (or something else)as regex delimiters.
     
    Dave, Oct 27, 2005
    #2
    1. Advertising

  3. Dave Guest

    "Dave" <> wrote in message
    news:43612527$0$1012$...
    >
    > <> wrote in message
    > news:...
    >> Code:
    >>
    >> if
    >> (
    >> $x =~
    >> /
    >> \d+ # this slash / generates an error
    >> /x
    >> )
    >> {
    >> }
    >>
    >> version:
    >> activestate perl 5.8.7
    >>
    >> regards,
    >> Kiriakos Georgiou
    >>

    >
    > This is not a bug. The compiler doesn't see the /x switch until it has
    > found the limits of the regex, so the / in the comment gives it a false
    > ending (see the footnote on p148 of the camel book). If you want to use /
    > in your comments use {} (or something else)as regex delimiters.
    >
    >


    and also the perlre manpage where the /x switch is explained says:

    Note that you have to be careful not to include the pattern delimiter in
    the comment--perl has no way of knowing you did not intend to close the
    pattern early
     
    Dave, Oct 27, 2005
    #3
  4. Paul Lalli Guest

    wrote:
    > Code:
    >
    > if
    > (
    > $x =~
    > /
    > \d+ # this slash / generates an error
    > /x
    > )
    > {
    > }
    >
    > version:
    > activestate perl 5.8.7


    I don't know how you can call it a bug when this limitation of the /x
    feature are perfectly well documented in
    `perldoc perlre`

    Paul Lalli
     
    Paul Lalli, Oct 27, 2005
    #4
    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. Replies:
    0
    Views:
    1,157
  2. Replies:
    4
    Views:
    117
  3. Joseph L. Casale

    Robust regex

    Joseph L. Casale, Nov 19, 2012, in forum: Python
    Replies:
    2
    Views:
    171
    Joseph L. Casale
    Nov 19, 2012
  4. Chris Angelico

    Re: Robust regex

    Chris Angelico, Nov 19, 2012, in forum: Python
    Replies:
    0
    Views:
    151
    Chris Angelico
    Nov 19, 2012
  5. MRAB

    Re: Robust regex

    MRAB, Nov 19, 2012, in forum: Python
    Replies:
    0
    Views:
    149
Loading...

Share This Page