Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: regex negative lookahead behaviour

by pijll (Beadle)
on Jul 19, 2003 at 11:49 UTC ( [id://275858]=note: print w/replies, xml ) Need Help??


in reply to Re: regex negative lookahead behaviour
in thread regex negative lookahead behaviour

The only thing that overrides a regexes natural greediness is it's desire to achieve a match.
Normal regexes are greedy, but not selfish; they are willing to give characters back if it's for the greater good.

But you can use the (?>pattern) construct to create "selfish" regexes: they only try to match once at every position. If the pattern inside is greedy, it will never give up chars to make the entire regex match; if the pattern is lazy, it will never match more than the absolute minimum of chars at that position.

So "1/2 MILE" =~ m[1/2(?>\s*)(?!MILE)] should work.

Log In?
Username:
Password:

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

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

    No recent polls found