"be consistent" | |
PerlMonks |
Re^2: Using negative lookaheadby ibm1620 (Hermit) |
on Oct 19, 2017 at 22:57 UTC ( [id://1201712]=note: print w/replies, xml ) | Need Help?? |
I'm still having trouble grasping this. Let me try and restate what your solution is doing:
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, .* ?
In Section
Seekers of Perl Wisdom
|
|