Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to modify my regex?

by Laurent_R (Canon)
on Aug 26, 2015 at 20:25 UTC ( [id://1140115]=note: print w/replies, xml ) Need Help??


in reply to How to modify my regex?

AnomalousMonk said it all, but just to put it in other terms, you want your regex to stop at the first occurrence of the regex end delimiter (I mean the end of the pattern), rather that the last one.

So simply:

my $regex = '%17\{#MARKERS.*?MARKERS#}';
With the ? qualifier, the regex engine is no longer going to match as much as possible, i.e. up to the very last occurrence of the MARKERS#} end delimiter, but will be happy to stop at the first one, which is what you need here. Actually, when quantifying . any character symbol, the .* or the .+ pattern is relatively rarely what you want, quite often .*? and .+? are better. But that's not a general rule, there also cases when you want to match up to the end of the last regex end delimiter.

Replies are listed 'Best First'.
Re^2: How to modify my regex?
by OldChamp (Acolyte) on Aug 26, 2015 at 20:57 UTC

    Hi Laurant_R, thank you for your clear explanation.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found