Python:尝试缩小字符串并除去空格以外的非字母数字字符

Python:尝试缩小字符串并除去空格以外的非字母数字字符,第1张

Python:尝试缩小字符串并除去空格以外的非字母数字字符

你可以用这个

re.sub(r'[^sa-zA-Z0-9]', '', text).lower().strip()

例:

>>> import re>>> def removePunctuation(s):        return re.sub(r'[^sa-zA-Z0-9]', '', s).lower().strip()>>> print removePunctuation('Hi, you!')hi you>>> print removePunctuation(' No under_score!')no underscore

要么

re.sub('(?!s)[W_]', '', text).lower().strip()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5661840.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存