Python正则表达式匹配Unicode属性 [英] Python regex matching Unicode properties

查看:81
本文介绍了Python正则表达式匹配Unicode属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Perl 和其他一些当前的正则表达式引擎在正则表达式中支持 Unicode 属性,例如类别.例如.在 Perl 中,您可以使用 \p{Ll} 匹配任意小写字母,或使用 p{Zs} 匹配任何空格分隔符.我在 Python 的 2.x 和 3.x 行中都没有看到对此的支持(对此表示遗憾).有人知道获得类似效果的好策略吗?欢迎使用本土解决方案.

Perl and some other current regex engines support Unicode properties, such as the category, in a regex. E.g. in Perl you can use \p{Ll} to match an arbitrary lower-case letter, or p{Zs} for any space separator. I don't see support for this in either the 2.x nor 3.x lines of Python (with due regrets). Is anybody aware of a good strategy to get a similar effect? Homegrown solutions are welcome.

推荐答案

你试过 Ponyguruma,与 Oniguruma 正则表达式引擎的 Python 绑定?在该引擎中,您可以简单地说 \p{Armenian} 来匹配亚美尼亚语字符.\p{Ll}\p{Zs} 也可以.

Have you tried Ponyguruma, a Python binding to the Oniguruma regular expression engine? In that engine you can simply say \p{Armenian} to match Armenian characters. \p{Ll} or \p{Zs} work too.

这篇关于Python正则表达式匹配Unicode属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆