[英]Regex Ignore numbers in a string (python)
我有这样的文字:
text = "hey , i am new here . number is 8,5%"
我希望我的 output 是这样的:
hey, i am new here. number is 8,5%
所以我使用这个正则表达式代码:
text= re.sub(r'\s*([.,?:])\s*', r'\1 ',text)
该代码的output为:
hey, i am new here. number is , 5%
我不希望我的正则表达式代码触及这些数字。
我正在使用 Python3
您可以使用(?<.\d)\s*([,?::])\s*
。
(?<!\d)
表示“如果前面没有数字”
完整代码: text= re.sub(r'\s*([.,?:])\s*', r'\1 ',text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.