【发布时间】:2019-11-08 07:15:32
【问题描述】:
这是对任何正则表达式结果的限制吗?
我需要的是在一行中获得所有出现,但preg_match_all 返回表达式的第一个和结尾。
有没有其他方法可以让所有的出现都上线?
$re = "/(media|images)(.*)(.jpg|.jpeg|.png)/";
$str = 'images/test/test-1.png" alt="test-1" /></a><a href="/test-2" title="test 2"><img src="/images/test/test2.png" alt="test2" /></a> <a href="/test-3" title="Cruises in Croatia"><img src="/images/EET/test-3.png';
preg_match_all($re,$str,$matches );
print_r($matches);
这就是我得到的。
Array
(
[0] => Array
(
[0] => images/test/test-1.png" alt="test-1" /></a><a href="/test-2" title="test 2"><img src="/images/test/test2.png" alt="test2" /></a> <a href="/test-3" title="Cruises in Croatia"><img src="/images/EET/test-3.png
)
[1] => Array
(
[0] => images
)
[2] => Array
(
[0] => /test/test-1.png" alt="test-1" /></a><a href="/test-2" title="test 2"><img src="/images/test/test2.png" alt="test2" /></a> <a href="/test-3" title="Cruises in Croatia"><img src="/images/EET/test-3
)
[3] => Array
(
[0] => .png
)
)
【问题讨论】:
-
get all the occurrence in a single line是什么意思?你得到的是预期的行为,它会给你一个包含所有匹配的数组,匹配意味着每个捕获组的每个匹配 -
你想获取所有图片路径吗?
标签: php regex preg-match-all