anu*_*Gak 4 regex python-2.7 regex-lookarounds
命令
re.compile(ur"(?<=,| |^)(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)
抛出一个
sre_constants.error: look-behind requires fixed-width pattern
我的程序中出现错误,但是regex101显示它很好。
我在这里尝试做的是匹配地址中的地标(每个地址在单独的字符串中),例如:
后面是避免opp
在其中匹配单词(如字符串3)。
为什么会引发该错误?除了我要找的东西以外,还有其他选择吗?
re.compile(ur"(?:^|(?<=[, ]))(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)
您可以3
使用[]
和查看条件|
。
https://regex101.com/r/vA8cB3/2#python