Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Unable to constrain the effect of a negative lookahead

by hv (Prior)
on Apr 15, 2022 at 02:39 UTC ( [id://11142990]=note: print w/replies, xml ) Need Help??


in reply to Unable to constrain the effect of a negative lookahead

But what I think is really happening is that when the pattern (?!.*batch\s*=) is encountered, despite being within a parenthesized group, its effect extends beyond those parentheses, effectively setting the condition that from that point in the regex to the end of the regex there can be no “batch =” pattern present.

Close - but it's "from that point in the string to the end of the string". The fragment (?!.*batch\s*=) means "match at this point in the string only if at this point we do not satisfy /.*batch\s*=/". There's no scoping going on - the whole of the string (from the point we've matched to so far) is fair game. So this fragment can only match locations in the string that don't have a "batch =" anywhere after them, and since the second half of the pattern requires "batch", we have a contradiction and the whole will never match.

Replies are listed 'Best First'.
Re^2: Unable to constrain the effect of a negative lookahead
by fireblood (Scribe) on Apr 15, 2022 at 11:42 UTC
    Hi hv, Yes, you stated it quite well, that's what I meant to say but was sloppy in using the phrase "that point in the regex" instead of "that point in the string". Thanks for the correction. And you have also confirmed what I suspected was the problem, that because the effect of the /?!.*batch/ was over the entire string rather than the part of the string to which the parenthesized expression applied (such as (?i) for temporarily matching case insensitively) the expression as a whole contained a contradiction and the whole would never match. -fireblood

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found