Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Re: negative Lookahead

by wog (Curate)
on Nov 12, 2001 at 08:15 UTC ( [id://124737]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: negative Lookahead
in thread negative Lookahead or

What appears to be happening with the second string is this:

You match HIT. Then you go looking matching [^<]*?. The *? first tries to match the minimal number of characters, so it gets 0. And, the negative look-ahead does not try to do backtracking to make that *? match more so it can make the negative look-ahead match. (update: because, if it did that, then the look-ahead would be doing more then just looking ahead in the string.) Thus, it doesn't find a match and the negative lookahead succeeds, so the positive lookahead succeeds.

Replies are listed 'Best First'.
Re: Re: Re: Re: negative Lookahead
by eddmund (Initiate) on Nov 12, 2001 at 21:00 UTC
    OK, thanks. Considering switching to greedy instead of non-greedy results in the regex
    $string =~ / ( HIT (?= [^<]* (?! <a[^>]*> ) .*?<\/a> ) .*?<\/a> ) /x;
    but still gives the same results. If the $string
    '<a href="#1">--HIT<a name="MUST NOT MATCH">--</a> <a href="#2">2</a>'
    does properly not match and
    '<a href="#1">--HIT-<a name="MUST NOT MATCH">--</a> <a href="#2">2</a> +'
    does "falsely" match I don't understand why the problem lies in the fact that a negative lookahead does not backtrack.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-18 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found