1.有个坑 re.sub('[^\w]', ' ', 'hello world, get rid of comma') --> [^\w] 非字符的意思
[^abc] 匹配除了a,b,c之外的字符
import re
text_string = re.sub(r'([^\s\w]|_|[0-9])+',''," I 3 _ I 3 ? _ love you")
print (text_string)
I I love you
用一个例子来演示会更加清晰
1.有个坑 re.sub('[^\w]', ' ', 'hello world, get rid of comma') --> [^\w] 非字符的意思
[^abc] 匹配除了a,b,c之外的字符
import re
text_string = re.sub(r'([^\s\w]|_|[0-9])+',''," I 3 _ I 3 ? _ love you")
print (text_string)
I I love you
用一个例子来演示会更加清晰
下一篇:(转) VSCODE:删除空白行
字符串替换空格-python
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M