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

It is greedy.

b{0,2} can't magically skip ahead to match characters in a different location in the string; it's constrained to matching at the current position. With that in mind, the match operation matches an a at position 0, then an a at position 1, then zero b at position 2. It wants to match two of them (since it's greedy), but there aren't any to match at position 2! So it settles for matching zero (which you allowed it to do).

It doesn't match one b as you claim.


Note that your usage of (?{ }) won't work in general. Consider the following:

"abdabbc" =~ /a(?:b(?{ say "b"; }))+c/

This prints three b even though the pattern only matches two. To get the correct count, you need

"abdabbc" =~ /a(?:b(?{ local $c = $c + 1; }))+c(?{ say $c; })/