带有lookbehind和lookahead的Python正则表达式不起作用

Jiv*_*van 2 python regex

我有一个 Python在debuggexregex中运行良好:

在此输入图像描述

但是,当我在 Python 控制台中执行此操作时:

import re
rgx = re.compile(r'(?<="careerJobAdsList", ){"jobAds":.*}](?=,"nodes":)')

st = 'widget("careerJobAdsList", {"jobAds":[{"id":607}],"nodes":[{"id":2,"parent_id"'

rgx.match(st)
>>> None
Run Code Online (Sandbox Code Playgroud)

我尝试转义 中的所有特殊字符rgx,但它不会改变输出。

我错过了什么吗?

roc*_*987 5

match在字符串开头查找匹配项。改用search

print(rgx.search(st))
Run Code Online (Sandbox Code Playgroud)

引用重赛

如果字符串开头的零个或多个字符与正则表达式模式匹配,则返回相应的 MatchObject 实例。如果字符串与模式不匹配,则返回 None;请注意,这与零长度匹配不同。

Python代码

import re
rgx = re.compile(r'(?<="careerJobAdsList", ){"jobAds":.*}](?=,"nodes":)')
st = 'widget("careerJobAdsList", {"jobAds":[{"id":607}],"nodes":[{"id":2,"parent_id"'
print(rgx.search(st))
Run Code Online (Sandbox Code Playgroud)