python 中的 ICU 正则表达式
ICU regex in python
是否可以在 python3 中 运行 ICU 兼容正则表达式?
例如,以下正则表达式不适用于默认 python 的正则表达式库,但适用于 C++ ICU 库:
import re
re.compile("(?<=(AA|BBB)12345)")
# Result: sre_constants.error: look-behind requires fixed-width pattern
我有许多为 ICU 正则表达式库编写的正则表达式,我想 运行 python。任何人都知道如何做或如何将它们自动迁移到 python 正则表达式格式?
非常感谢!
Wiktor 在上面的评论中给出的解决方案有效。
复制:
- 安装正则表达式库:pip install regex
- 运行 python shell 中的以下内容:
>>> import regex
>>> r=regex.compile("(?<=(AA|BBB)12345)")
>>> r.findall('AA12345')
['AA']
>>> r.findall('BBB12345')
['BBB']
>>> r.findall('CCC12345')
[]
是否可以在 python3 中 运行 ICU 兼容正则表达式? 例如,以下正则表达式不适用于默认 python 的正则表达式库,但适用于 C++ ICU 库:
import re
re.compile("(?<=(AA|BBB)12345)")
# Result: sre_constants.error: look-behind requires fixed-width pattern
我有许多为 ICU 正则表达式库编写的正则表达式,我想 运行 python。任何人都知道如何做或如何将它们自动迁移到 python 正则表达式格式?
非常感谢!
Wiktor 在上面的评论中给出的解决方案有效。 复制:
- 安装正则表达式库:pip install regex
- 运行 python shell 中的以下内容:
>>> import regex >>> r=regex.compile("(?<=(AA|BBB)12345)") >>> r.findall('AA12345') ['AA'] >>> r.findall('BBB12345') ['BBB'] >>> r.findall('CCC12345') []