你可以用这个
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()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)