gpt4 book ai didi

Python 正则表达式大写 unicode 字

转载 作者:太空狗 更新时间:2023-10-30 01:55:18 24 4
gpt4 key购买 nike

我需要查找多种语言的缩写文本。当前 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com