小编Wkh*_*han的帖子

使用 re.sub 替换多个字符

s = "Bob hit a ball!, the hit BALL flew far after it was hit."
Run Code Online (Sandbox Code Playgroud)

我需要从 s 中删除以下字符

!?',;.
Run Code Online (Sandbox Code Playgroud)

如何使用 re.sub 来实现这一点?

re.sub(r"!|\?|'|,|;|."," ",s) #doesn't work. And replaces all characters with space
Run Code Online (Sandbox Code Playgroud)

有人能告诉我这有什么问题吗?

python regex string python-2.7

5
推荐指数
1
解决办法
6780
查看次数

标签 统计

python ×1

python-2.7 ×1

regex ×1

string ×1