我需要查找多种语言的缩写文本。当前 regex是:
import regex as re
pattern = re.compile('(?:[\w]\.)+', re.UNICODE | re.MULTILINE | re.DOTALL | re.VERSION1)
pattern.findall("U.S.A. u.s.a.")
我不需要结果中的 u.s.a,我只需要大写文本。 [A-Z] 不适用于英语以外的任何语言。
最佳答案
您需要使用 Unicode 字符属性才能匹配它们。 re
不支持字符属性,但是regex
>>> regex.findall(ur'\p{Lu}', u'ÜìÑ')
[u'\xdc', u'\xd1']
关于Python 正则表达式大写 unicode 字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12593509/