[英]Python regex with lookbehind and lookahead not working
我有一个Python regex
在debuggex中工作得很好:
但是,当我在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
我试图逃避rgx
所有特殊字符,但它不会改变输出。
我错过了什么吗?
match
在字符串的开头找到匹配项。 请改用search
print(rgx.search(st))
引用re.match
如果字符串开头的零个或多个字符与正则表达式模式匹配,则返回相应的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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.