【发布时间】:2019-06-10 06:38:16
【问题描述】:
我想从我的字符串中删除字符 \\。我试过 regextester 并且匹配,https://regex101.com/r/euGZsQ/1
s = '''That\\'s not true. There are a range of causes. There are a range of issues that we have to address. First of all, we have to identify, share and accept that there is a problem and that we\\''''
pattern = re.compile(r'\\{2,}')
re.sub(pattern, '', s)
我希望 sub 方法用什么来替换我的 \\ 来清理我的字符串。
【问题讨论】:
-
如果只想删除 '\\' 为什么不替换它呢? s.replace("\\\\", "")