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