首页 文章

Python正则表达式大写unicode字

提问于
浏览
4

我需要找到许多语言的缩写文本 . 目前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] 除英语外不会使用任何语言 .

1 回答

  • 11

    您需要使用Unicode字符属性才能匹配它们 . re 不支持字符属性,但regex支持 .

    >>> regex.findall(ur'\p{Lu}', u'ÜìÑ')
    [u'\xdc', u'\xd1']
    

相关问题