【发布时间】:2021-10-11 03:25:08
【问题描述】:
我有一些带有多个“.”的句子。
如何删除所有特殊字符和 '.'数据中除小数点外?
输入示例是
What? The Census Says It’s Counted 99.9 Percent of Households. Don’t Be Fooled.
我想删除所有“。” s 和特殊字符,小数点除外'。'
输出应该是这样的
What The Census Says Its Counted 99.9 Percent of Households Dont Be Fooled
我试过了,
regex = re.compile('[^ (\w+\.\w+)0-9a-zA-Z]+')
regex.sub('', test)
但是输出是
What The Census Says Its Counted 99.9 Percent of Households. Dont Be Fooled.
【问题讨论】:
-
您不能将组放在括号中。试试 '[^ .0-9a-zA-Z]+'。
标签: python-3.x regex regex-group regexp-replace nsregularexpression