[issue41885] Unexpected behavior re.sub() with raw f-strings

Matthew Barnett report at bugs.python.org
Tue Sep 29 11:35:02 EDT 2020


Matthew Barnett <python at mrabarnett.plus.com> added the comment:

Arguments are evaluated first and then the results are passed to the function. That's true throughout the language.

In this instance, you can use \g<1> in the replacement string to refer to group 1:

re.sub(r'([a-z]+)', fr"\g<1>{REPLACEMENT}", 'something')

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41885>
_______________________________________


More information about the Python-bugs-list mailing list