in reply to Re^2: how to replace a matched pattern in a string with a different pattern of same length?
in thread how to replace a matched pattern in a string with a different pattern of same length?

$s = '00110011111110111111111111111110';; my $best = [0,0];; $+[0] - $-[0] > $best->[1] and $best = [ $-[0], $+[0] - $-[0] ] while $s =~ m[(1+)]g;; substr $s, $best->[0], $best->[1], '2'x$best->[1];; print $s;; 00110011111110222222222222222220

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: how to replace a matched pattern in a string with a different pattern of same length?
  • Download Code