python 代码
功能如下:
将string里的所有的标点符号全部去除,只剩下英文字母,空格和数字
直接上代码:
# -*- coding: utf-8 -*-
import re
# make English text clean
def clean_text(text):
# keep English, digital and space
# 就是会把标点符号全部去除掉
comp = re.compile('[^A-Z^a-z^0-9^ ]')
return comp.sub('', text)
sentence='Hello! Dear world! I am happy today... Okay, fine, actually, that is not.'
output=clean_text(sentence)
print(output)
#Hello Dear world I am happy today Okay fine actually that is not
最后output的结果就是
Hello Dear world I am happy today Okay fine actually that is not
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)