[英]php - extract text between parenthesis, single quotes and double quotes
I want to extract text between parenthesis, single quotes and double quotes.我想提取括号、单引号和双引号之间的文本。 I have made it for single and double quotes, but I cant make it for the third parameter, parenthesis:
我已经为单引号和双引号制作了它,但我无法为第三个参数括号制作它:
for example:例如:
<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>
I want to extract:我想提取:
/path/to/the/file.jpg
/path/to/the/file2.png
/path/to/the/file555.gif
and this is the regex expression I am using:这是我正在使用的正则表达式:
preg_match_all('/(["\'])(.*(?:\.jpg|\.png|\.gif))\1/m', $subject, $matches)
or even this one:甚至这个:
preg_match_all('/(["\'])([^"\']*(?:\.jpg|\.png|\.gif))\1/m', $subject, $matches)
(?<=['"\(])[^"())\n']*?(?=[\)"'])
You can use this.See demo.你可以使用这个。看演示。
https://regex101.com/r/cD5jK1/12 https://regex101.com/r/cD5jK1/12
$re = "/(?<=['\"\\(])[^\"()\\n']*?(?=[\\)\"'])/m";
$str = "<img src=\"/path/to/the/file.jpg\"></div>\n<img src='/path/to/the/file2.png'></div>\n<div style=\"background:url(/path/to/the/file555.gif)\"></div>";
preg_match_all($re, $str, $matches);
您还可以使用正则表达式:
[\"\'\(]+(\/[^\/]+\/[^\/]+\/[^\/]+\/[^\.]+\.(?:jpg|gif|png))[\)\"\']+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.