【问题标题】:Python regex uppercase unicode wordPython正则表达式大写unicode字
【发布时间】:2017-01-23 19:15:05
【问题描述】:

我需要查找多种语言的缩写文本。当前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] 无法使用英语以外的任何语言。

【问题讨论】:

标签: python regex


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 2016-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 2016-01-21
  • 1970-01-01
相关资源
最近更新 更多