Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
XP is just a number
 
PerlMonks  

Re: On zero-width negative lookahead assertions

by pbeckingham (Parson)
on Sep 10, 2004 at 14:14 UTC ( #390078=note: print w/ replies, xml ) Need Help??


in reply to On zero-width negative lookahead assertions

The following works if you break it into two expressions, but I can't see why yours doesn't match.

perl -ne '/^root:\s*/ and $_ !~ /admin\@somewhere\.here/ and print' +alias
Update: Moving it around also works:
perl -ne '/^root:(?!\s*admin\@somewhere\.here)/ and print' alias



pbeckingham - typist, perishable vertebrate.


Comment on Re: On zero-width negative lookahead assertions
Select or Download Code
Re^2: On zero-width negative lookahead assertions
by bronto (Priest) on Sep 10, 2004 at 14:25 UTC
    perl -ne '/^root:\s*/ and $_ !~ /admin\@somewhere\.here/ and print' alias

    That's ok, but I want to understand that blah-blah-look-ahead thing

    perl -ne '/^root:(?!\s*admin\@somewhere\.here)/ and print' alias

    This works! But I can't understand why it doesn't work if you put the \s* outside the parens, nor I can understand why it stops working if I put the \s*$ at the end of the regex :-(

    Thanks a lot

    Ciao!
    --bronto


    In theory, there is no difference between theory and practice. In practice, there is.

      > But I can't understand why it doesn't work if you put the \s* outside the parens, nor I can understand why it stops working if I put the \s*$ at the end of the regex :-(

      That is because if you have the string

      root: admin@somewhere.here 11111233333333333333333333

      and the RE

      /^root:\s*(?!\s*admin\@somewhere\.here)/ ABBBBBCCC

      then the part A in the RE matches the beginning of the string, part BBBBB matches 11111 ("root:") and CCC matches an empty string (not a space, a string with zero chars in it). After this empty string follows a space, and the space is not the beginning of "admin@somewhere.here", because it is the beginning of " admin@somewhere.here".

      I hope things are getting clearer for you :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://390078]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-04-19 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls