📌  相关文章
📜  如何查找和替换 Python 字符串中的所有标点符号 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:16.089000             🧑  作者: Mango

代码示例1
#import the regex library (pip install it with -> "pip install regex"
import re

test_phrase = 'This is a string! Bust it has punctuation. How can we remove it?'

#We're going to replace the punctution with a whitespace
clean = ' '.join(re.findall('[^!.?]+', test_phrase))
#                                 ^ Place the punctuation that you want
#                                  to remove in the square brackets.
print(clean)
> 'This is a string But it has punctuation How can we remove it'