How do you substitute a Python grab followed by a number character?

When using re.sub , how do you deal with a situation where you need a capture followed by a number in the replacement string? For example, you cannot use "\ 10" for capture 1, followed by the character "0", because it will be interpreted as capture 10.

+3
source share
1 answer
\g<1>0

http://docs.python.org/library/re.html#re.sub

\ g <number> ; , \g < 2 > \2, , \g < 2 > 0.\20 20, 2 "0".

+6

Source: https://habr.com/ru/post/1704836/


All Articles