【发布时间】:2015-04-07 02:05:17
【问题描述】:
我正在尝试在 python 中使用 re.sub 将一个字符替换为空行,但它抛出了一些错误
import re
string = "\asdfsdfsdf\dfd\f\df\df\d"
re.sub("\\","",string)
print (string)
输出:
Traceback (most recent call last):
File "variable_concat.py", line 4, in <module>
re.sub("\\","",string)
File "/usr/lib/python2.7/re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/lib/python2.7/re.py", line 244, in _compile
raise error, v # invalid expression
sre_constants.error: bogus escape (end of line)
哪里出错了
【问题讨论】:
标签: python regex replace str-replace