In Perl, I would write:
$x = "abbbc";
$x =~ s/(b+)/z/;
print "Replaced $1 and ended up with $x\n";
# "Replaced bbb and ended up with azc"
How do I do this in Python — do a regular-expression string replacement and record what it was that got replaced?
Python does not simultaneously return a match and a substitution. Calling
group(0)on a returned Match object will find the matched substring: