我需要找到许多语言的缩写文本 . 目前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支持 .
re
>>> regex.findall(ur'\p{Lu}', u'ÜìÑ') [u'\xdc', u'\xd1']
1 回答
您需要使用Unicode字符属性才能匹配它们 .
re
不支持字符属性,但regex支持 .