Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Must do regex range quantifier { } as a greedy

by Corion (Patriarch)
on Jan 17, 2022 at 08:39 UTC ( [id://11140517]=note: print w/replies, xml ) Need Help??


in reply to Must do regex range quantifier { } as a greedy

Using Regexp::Debugger, you can see that the regexp immediately matches at the start of the string, because aa (followed by zero b) matches.

If you want to match the aab, you can push the match to the right by preprending .*:

"aaabb" =~ /.*aa(b(?{{print "\nYes b letter"}})){0,2}/

Replies are listed 'Best First'.
Re^2: Must do regex range quantifier { } as a greedy
by LanX (Saint) on Jan 17, 2022 at 09:20 UTC
    Your elegant solution will match the rightmost case of "aab+" not the longest, but it's unclear to me whether that is relevant for the OP. ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found