我使用的是python2.X,从一个文件中加载一个文本,这是一行文本
Odio ¿Mañana pensar porque RT luego pasa lo que pasa Marzo ♡♡♡
我发现这个正则表达式[^\x30-\xFF]与我想要的字符完全匹配(使用在线regex工具),但是当我像这样在代码中使用它时:
filtered_comments = re.sub("[^\x30-\xFF]", " ", all_comments)
它不匹配相同的字符;您可以在http://pythex.org上尝试 所以在这篇文章中,我要匹配,然后留下niand .... 有什么想法吗?在
all_comments
是type
str
还是{unicode
类型并且字符打印正确,那么正则表达式应该可以工作。在如果字符串是
str
类型,则需要使用正确的编码对其进行编码。假设您的编码是UTF-8,这将起作用:另一件要注意的事情是:您}以及{}以下的许多其他符号。也许你想要
^\x30-\xFF
匹配!
和{^\x20-\xFF
,因为\x20
是空间,它几乎是最低的典型ASCII字符?在尝试下面的脚本,请在第一行看到
#coding=utf-8
。有关详细信息,请参见PEP-0263它会打印出来的
^{pr2}$相关问题 更多 >
编程相关推荐