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

Re^2: Using negative lookahead

by ibm1620 (Hermit)
on Oct 19, 2017 at 22:57 UTC ( [id://1201712]=note: print w/replies, xml ) Need Help??


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

I'm still having trouble grasping this. Let me try and restate what your solution is doing:
^ ( # capture delimiter in pos 1 ["'] # delim is single or double quote ) ((?!.*\g1.).*) # neg lookahead for delim \g1$ # finally, the delim
Pick up the delimiter character from pos 1, if there is one (otherwise fail)

Capture this in $2:

-- As many characters as possible (could be none)

-- that are NOT followed by the delimiter character and another character (which is the case of an embedded delimiter, which should be a fail)

-- and are followed by zero or more characters.

Beyond this should be the delimiter, at the end of the string.

I'm confused by the '.*' that's the last part of capture group $2. Why is it needed at all? Hasn't the preceding already consumed the payload that I want? I guess I'm not understanding the precise role that the negative lookahead is playing. Is it simply saying what the string picked up by .* must look like? Is there any significance to (?!.*\g1.) appearing *before*, rather than after, .* ?

Replies are listed 'Best First'.
Re^3: Using negative lookahead
by tybalt89 (Monsignor) on Oct 20, 2017 at 00:17 UTC

    Zero-width negative lookaheads do not advance the match point -> "zero-width".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-26 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found