Why does re.sub replace the entire pattern, not just a capturing group within it?
Why does re.sub replace the entire pattern, not just a capturing group within it? Question: re.sub(‘a(b)’,’d’,’abc’) yields dc, not adc. Why does re.sub replace the entire capturing group, instead of just capturing group'(b)’? Asked By: Nick || Source Answers: Because it’s supposed to replace the whole occurrence of the pattern: Return the string obtained by …