in reply to Re: Using negative lookahead
in thread Using negative lookahead
Pick up the delimiter character from pos 1, if there is one (otherwise fail)^ ( # capture delimiter in pos 1 ["'] # delim is single or double quote ) ((?!.*\g1.).*) # neg lookahead for delim \g1$ # finally, the delim
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 | |
by ibm1620 (Hermit) on Oct 20, 2017 at 14:19 UTC |