from string import punctuation
import re
puncrx = re.compile(r'[{}\s]'.format(re.escape(punctuation)))
print filter(None, puncrx.split(your_tweet))
或者,只需查找包含某些连续字符的单词:
^{pr2}$
例如:
print re.findall(r'[\w@#]+', 'talking about #python with @someone is so much fun! Is there a 140 char limit? So not cool!')
# ['talking', 'about', '#python', 'with', '@someone', 'is', 'so', 'much', 'fun', 'Is', 'there', 'a', '140', 'char', 'limit', 'So', 'not', 'cool']
{{cd1>你可以使用多个字符来分割}。。。在
或者,只需查找包含某些连续字符的单词:
^{pr2}$例如:
我最初在这个例子中有一个笑脸,但是当然,这些笑脸最终会被这个方法过滤掉,所以这是值得警惕的。在
在进行拆分之前,请尝试从字符串中删除标点符号。在
然后对
out
执行split
。在我建议在使用以下代码拆分文本之前清除特殊符号中的文本:
在使用函数sub之前,您需要导入re
^{pr2}$相关问题 更多 >
编程相关推荐