I was wondering if there is a way to pass a pattern with a group which can be replaced with what I need.
For example pattern <table class="(old_class)">
to be replaced with <table class="new_class">
without repeating the whole thing.
I can do
>>> re.sub(r'(.*?)regular expressions(.*?)', r'\1everything\2', 'I like regular expressions in Python.')
>>> 'I like everything in Python.'
I am looking for an elegant way to replace text matched by capture groups. I think this a common pattern and there should exist a built-in way for this instead of making my own function.
P.S. HTML is just an example.