有一种方法可以完成这项工作:
$input = <<<EOD
CSS:
ul li {
list-style-image: url('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
}
#insert { background-image: url('../img/insert.jpg'); }
#delete { background-image: url('../img/delete.png'); }
HTML:
<link rel="icon" sizes="192x192" href="touch-icon-192x192.png">
<img id="home" src="img/home.png" class="img-home">
JavaScript:
"BackgroundImageUrl": "textures/glass.jpg"
EOD;
preg_match_all('/(?<=["\'])[^"\']+?\.(?:jpe?g|png|gif)(?=["\'])/', $input, $m);
print_r($m);
输出:
Array
(
[0] => Array
(
[0] => ../img/insert.jpg
[1] => ../img/delete.png
[2] => touch-icon-192x192.png
[3] => img/home.png
[4] => textures/glass.jpg
)
)
说明:
(?<=["\']) : lookbehind, make sure we have a quote before
[^"\']+? : 1 or more any character that is not a quote
\. : a dot
(?:jpe?g|png|gif) : non capture group, list of image extensions
(?=["\']) : lookahead, make sure we have a quote after