When using re.sub, how to you handle 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 a '0' character because it will be interpreted as capture 10.
+5
A:
\g<1>0
http://docs.python.org/library/re.html#re.sub
\g<number> uses the corresponding group number; \g<2> is therefore equivalent to \2, but isn’t ambiguous in a replacement such as \g<2>0. \20 would be interpreted as a reference to group 20, not a reference to group 2 followed by the literal character '0'.
vartec
2009-03-16 15:40:27