unicode findall python

bad*_*0re 4 python regex

我有一个英语语言的工作模式,但由于我的母语不起作用,这让我很头疼.首先,我打开了许多关于编码的问题,我知道我低估了它,这是一个大问题.我花了一些时间阅读它,问题仍然存在.所以现在我正面临一个正则表达问题.所以模式是:

exactMatch = re.compile(r"([^\.]*\b???????\b[^\.]*)\.", re.UNICODE)
print exactMatch.pattern
result= exactMatch.findall("??????? ? ?? ????? ?? ????????????. ??????? ? ?? ????? ?? ????????????.")
Run Code Online (Sandbox Code Playgroud)

它适用于英语.它的功能是给我一个段落中的所有句子.那有什么建议吗?

我也试过编码和解码,但注意到编码错误除外.

mat*_*ata 6

这将工作:

exactMatch = re.compile(ur"([^\.]*\b???????\b[^\.]*)\.", re.UNICODE)
print exactMatch.pattern
result= exactMatch.findall(u"??????? ? ?? ????? ?? ????????????. ??????? ? ?? ????? ?? ????????????.")
Run Code Online (Sandbox Code Playgroud)

如果你使用unicode,那么使用 unicode.

  • 你得到什么错误?这个对我有用.另外,请确保您的文件具有[正确的编码集](http://www.python.org/peps/pep-0263.html). (2认同)