Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Why is this regex greedy?

by chromatic (Archbishop)
on Jul 02, 2004 at 20:32 UTC ( [id://371502]=note: print w/replies, xml ) Need Help??


in reply to Why is this regex greedy?

The regex engine prefers leftmost, longest matches. Nothing in your regex prevents it from matching everything between the first slash and the end of line.

Replies are listed 'Best First'.
Re^2: Why is this regex greedy?
by pbeckingham (Parson) on Jul 02, 2004 at 20:34 UTC

    So it is not treating that .+? the way I expected? Even though there are more-minimal matches?

    I guess leftmost-longest trumps non-greedy.

      Right and right.

      I don't understand why people expect non-greedy matching to actually mean "globally shortest match". Perhaps it's in the language we use. Just keep the left-to-rightness as the most prominent feature of your mental model of how perl's RE engine works and you shouldn't go wrong though.

Log In?
Username:
Password:

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

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

    No recent polls found