如何在Python中通过正则表达式对文本进行分词
有没有什么方法可以用正则表达式来清理文本中的空格、句点和逗号,而不使用NLTK库呢?
1 个回答
1
如果我理解你的问题没错的话,你可以试试这段代码
import re
text = "Split.this,text in seven.separate,words"
myexp=re.compile(r'[\s.,]')
print myexp.split(text)
这样可以得到这个结果
['Split', 'this', 'text', 'in', 'seven', 'separate', 'words']