Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: regex: negative lookahead

by svenXY (Deacon)
on Dec 05, 2011 at 16:08 UTC ( #941887=note: print w/replies, xml ) Need Help??


in reply to Re: regex: negative lookahead
in thread regex: negative lookahead

Hi,
++kennethk - thanks for clarifying. I'm still a little bit confused by the difference between (?!...) and (?<!...) though.
Regards,
svenXY

Replies are listed 'Best First'.
Re^3: regex: negative lookahead
by kennethk (Abbot) on Dec 05, 2011 at 16:38 UTC
    The difference is a lookahead versus a lookbehind. If you ignore the lookahead/lookbehind because they are zero width (don't consume characters), you would expect /^($start(\w+(,\s)?)+)$/ to grab an entire string between start and finish. When you get to the part of the regular expression where you have your assertion, the cursor is here:
    log4j.rootLogger=INFO, FILE, SYSLOG ^
    If you look ahead of this position, there is nothing, which clearly passes the negative lookahead check. The offending string is behind your position, thus you need a negative lookbehind.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://941887]
help
Chatterbox?
[atcroft]: .oO(It is a well-known, well-tried module that has probably encountered more corner-cases and oddities than the average mortal programmer can imagine when trying to roll their own...)
[atcroft]: .oO(*Blah* It, I meant....)
[james28909]: omg
[james28909]: im just finding out that july and august have 31 days?
[atcroft]: stevieb: Apparently it was contagious....
[atcroft]: james28909: Make both hands into fists, place them together (with thumbs concealed), and every knuckle is a month (starting with Jan.) has 31 days, every dip (between knuckles) does not....
[atcroft]: (And Feb. is the odd case, because it is 28, unless it is a year divisible by 4, or if it is divisible by both 100 and 400 (at which point it is 29).)
[james28909]: i know but scroll through your calendar on your computer.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2017-04-29 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.