Matthew Barnett added the comment:
Yes, the second argument is a replacement template, not a literal.
This issue does point out a different problem, though: re.escape will add
backslashes that will then be treated as literals in the template, for example:
>>> re.sub(r'a', re.escape('(A)'), 'a')
'\\(A\\)'
re.escape doesn't always help.
The solution here is to pass a replacement function instead:
>>> re.sub(r'a', lambda m: '(A)', 'a')
'(A)'
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com