Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Regex a little less greedy please

by arturo (Vicar)
on Mar 18, 2003 at 14:29 UTC ( #243988=note: print w/replies, xml ) Need Help??


in reply to Regex a little less greedy please

From perlre :

If you want it to match the minimum 
number of times possible, follow the 
quantifier with a "?".  Note that the 
meanings donít change, just the 
"greediness"

So, changing your regex to

<APPEND.*?>
Should get you the behavior you want. If, however, you take to heart the lessons of Death to Dot Star!, you might want to write that this way:
<APPEND[^>]*>
Avoiding using the post-match variable and using () to capture the stuff you want to get is left as an exercise for the reader =)

HTH

If not P, what? Q maybe?
"Sidney Morgenbesser"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2023-05-31 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?