python 正则 替换非字符串成空格


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

参考:https://www.cnblogs.com/12260420zxx/p/13663291.html
https://blog.csdn.net/u010211479/article/details/78490854

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM