Skip to content
Prev 168787 / 398503 Next

sub question

David Hajage wrote:
to extend the context, if you were to solve the problem in perl, the
regex below would work in perl 5.10, but not in earlier versions of
perl;  another approach is to replace the unwanted leading characters
with equally many replacement characters at once.

$string = 'aabaab';

# perl 5.10
$string =~ s/a|(*COMMIT)(*FAIL)/c/g
# $string is 'ccbaab'

# any recent perl
$string =~ s/^a*/'c' x length $&/e;
# $string is 'ccbaab'

i don't know how (if) the latter could be done in r.

vQ