in reply to Greedy Substitution Within a Defined Range
This repeats the search and replace until it isn't found anymore. Not exactly "within one regex" but it is still pretty readable.1 while $text =~ s/(BEGIN_MARKER(?:(?!END_MARKER).)*?)a(.*?END_MARKER) +/$1x$2/;
The part which reads (?:(?!END_MARKER).)*? will non-greedily accept any characters that aren't starting your end marker. It's a negative-lookahead inside a non-capturing group.
--
[ e d @ h a l l e y . c c ]
|
|---|