使用 re.sub 时,您如何处理需要捕获后跟替换字符串中的数字的情况?例如,您不能将“\10”用于后跟“0”字符的捕获 1,因为它将被解释为捕获 10。
最佳答案
\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'.
关于python - 您如何替换后跟数字字符的 Python 捕获?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/650926/