import re old = 'regexregex' new = re.sub(r'regex(group)?regex', r'something\1something', old) print(new)
Standard input is empty
Standard output is empty
Traceback (most recent call last): File "prog.py", line 3, in <module> File "/usr/lib/python2.7/re.py", line 155, in sub return _compile(pattern, flags).sub(repl, string, count) File "/usr/lib/python2.7/re.py", line 291, in filter return sre_parse.expand_template(template, match) File "/usr/lib/python2.7/sre_parse.py", line 831, in expand_template raise error, "unmatched group" sre_constants.error: unmatched group