Php 按id bbcode列出的img url

Php 按id bbcode列出的img url,php,regex,bbcode,Php,Regex,Bbcode,我想通过特定ID从src atribute获取链接 例如,我有以下bbcode标记: [img alt="" src="http://google.com" id="image"] [img src="http://google.com" id="image2" alt=""] [img id="image3" src="http://google.com" alt=""] 我用\[img(?:[^]]+src=“(.+?)”[^]+(?:id | class)=“image”|[^]+(?:

我想通过特定ID从src atribute获取链接

例如,我有以下bbcode标记:

[img alt="" src="http://google.com" id="image"]
[img src="http://google.com" id="image2" alt=""]
[img id="image3" src="http://google.com" alt=""]
我用
\[img(?:[^]]+src=“(.+?)”[^]+(?:id | class)=“image”|[^]+(?:id | class)=“image”[^]]+src=“(.+?)”

但对于第二个图像,它不起作用


你可以试试这样的方法()


使用标志g和m。唯一的缺点是,在这种情况下,您需要同时检查捕获组1和2以查找url。当src位于id属性之前时,匹配项存储在组1中,但当id属性位于src之前时,url存储在组2中。

删除“单线”标志。@horcrux是的,这就是问题所在,因为我有单线文本。。。也许我可以在每一个后面加一个“
”?或者用“
[^]]
代替我的两个
@chris85”BBCodes@horcrux我不明白。。六羟甲基三聚氰胺六甲醚
\[img\s(?:.*?src="(.*?)".*?)?id="image"(?:.*?src="(.*?)".*?)?[^\]]*]