Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Negative Lookahead Assertion Strangness

by kvale (Monsignor)
on May 15, 2006 at 16:37 UTC ( [id://549541]=note: print w/replies, xml ) Need Help??


in reply to Negative Lookahead Assertion Strangness

In example 3, the lookahead assertion doesn't match at the beginning of the string, so the regex tries to match at the next position in the string, that fails and so on. This continues until the regex matches at position "oo then..." in which case no foo is found and it succeeds.

In example 4, the .* will first eat the whole string and then the foo will fail to match, satisfying the negative assertion :). So the whole string is printed.

Both of these examples show the danger of creating nonlocal assertions. It is easy to do something unexpected when the string tested is some distance from the assertion.

-Mark

  • Comment on Re: Negative Lookahead Assertion Strangness

Log In?
Username:
Password:

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

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

    No recent polls found