通过lookbehind和lookahead查找 preg_match_all
我当前行
preg_match_all('/(?<=, ")<b>[\d\D]+(?="\)\;})/',$str,$matches);
$str 等于
906), "tadam tadam 393943");});
由于某种原因,它找不到匹配项,怎么样?
更新
为了使其正常工作,我需要将 U 添加到
正则表达式的末尾,所以它不会贪婪......
想想吧。
I have the current line
preg_match_all('/(?<=, ")<b>[\d\D]+(?="\)\;})/',$str,$matches);
where as $str is equal to
906), "<b>tadam tadam 393943</b>");});
for some reason it won't find matches, how is that?
UPDATE
In order for it to work I needed to add U at
the end of the regex, so it wouldn't be greedy...
go figure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它确实匹配,您只需用括号指定组:
这样就可以通过
$matches[1][ 访问匹配
。[\d\D]+
的片段0]It does match, you just have to specify the group with parentheses:
So that the fragment matching
<b>[\d\D]+
can be accessed via$matches[1][0]
.