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. ;-)