【发布时间】:2015-10-29 10:13:46
【问题描述】:
我想提取括号、单引号和双引号之间的文本。我已经为单引号和双引号做了它,但我不能让它用于第三个参数,括号:
例如:
<img src="/path/to/the/file.jpg"></div>
<img src='/path/to/the/file2.png'></div>
<div style="background:url(/path/to/the/file555.gif)"></div>
我要提取:
/path/to/the/file.jpg
/path/to/the/file2.png
/path/to/the/file555.gif
这是我正在使用的正则表达式:
preg_match_all('/(["\'])(.*(?:\.jpg|\.png|\.gif))\1/m', $subject, $matches)
甚至这个:
preg_match_all('/(["\'])([^"\']*(?:\.jpg|\.png|\.gif))\1/m', $subject, $matches)
【问题讨论】: