【发布时间】:2021-10-01 10:33:00
【问题描述】:
我想将此代码从 python2 移植到 python3
p = re.compile(ur"(?s)<u>(.*?)<\/u>")
subst = "\underline{\\1}"
raw_html = re.sub(p, subst, raw_html)
我已经发现ur 应该改为r:
p = re.compile(r"(?s)<u>(.*?)<\/u>")
subst = "\underline{\\1}"
raw_html = re.sub(p, subst, raw_html)
但是它不起作用它抱怨这个:
cd build && PYTHONWARNINGS="ignore" python3 ../src/katalog.py --katalog 1
Traceback (most recent call last):
File "src/katalog.py", line 11, in <module>
from common import *
File "src/common.py", line 207
subst = "\underline{\\1}"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape
make: *** [katalog1] Error 1
但是将其更改为 "\underline" 也无济于事。那时它不会取代它。
【问题讨论】:
标签: python python-3.x regex python-2.x