0
我有以下代碼:簡單的Python子
import re
Temp = "C4"
Num = 5
Temp = re.sub(r'(\w)\d',r'\1%s'%Num, Temp)
print Temp
我得到以下錯誤:
PS C:\...> .\try.py
Traceback (most recent call last):
File "C:\...\try.py", line 10, in <module>
Temp = re.sub(r'(\w)\d',r'\1%s'%Num, Temp)
File "C:\Python27\lib\re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "C:\Python27\lib\re.py", line 275, in filter
return sre_parse.expand_template(template, match)
File "C:\Python27\lib\sre_parse.py", line 802, in expand_template
raise error, "invalid group reference"
sre_constants.error: invalid group reference
我在做什麼錯在這裏?
謝謝FJ!這解決了問題。我花了數小時試圖弄清楚。 –