Here is my code:
In [1]: import re
In [2]: p = 'zxc(.*?)!(.*?)zxc'
In [3]: s = 'zxc wololo ! ololo zxc'
In [4]: re.sub(pattern=p, repl=r"", string=s)
Out[4]: ''
In [5]: re.sub(pattern=p, repl=r"\1", string=s)
Out[5]: ' wololo '
Expected
zxc wololo !zxc
Question
How to achieve the expected output?
I need to keep 1-st group with "prefix" and "suffix" of pattern. And let's assume that there are more then 2 groups.
Which keyword I should use in repl to achieve the expected result?
repl=r"zxc \1 !zxc"? See ideone.com/QbJ74Q and regex101.com/r/tzlx00/1