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

That's what you want?

DB<21> say 'aaabbbb' =~ /aa(?!a)b{0,2}/; say "<$&>" 1 <aabb>

Ranges are greedy by default, i.e. if they match at all.

BUT

DB<22> say 'aaaccccaaabbbb' =~ /aa(?!a)b{0,2}/; say "<$&>" 1 <aa>

Please elaborate...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Must do regex range quantifier { } as a greedy
by Corion (Patriarch) on Jan 17, 2022 at 08:41 UTC

    Your elegant solution won't match the edge case of aa, but it's unclear to me whether that is relevant for the OP.

      > won't match the edge case of aa

      hmm ... works for me

      DB<24> say 'aa' =~ /aa(?!a)b{0,2}/; say "<$&>" 1 <aa>

      or did you mean something else?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Aaah - I got tripped up by my own test harness. Yes, once I use your regular expression, it works for me as well.