开发者

Very simple editing in a regular expression pattern

开发者 https://www.devze.com 2023-02-21 15:45 出处:网络
How can I tranform this rege开发者_JS百科x to search only in src=* and not all the links that start with http and end with jpg, png, gif? Additionally I want to get the https images.

How can I tranform this rege开发者_JS百科x to search only in src=* and not all the links that start with http and end with jpg, png, gif? Additionally I want to get the https images. Thank you!

preg_match('!http://.+\.(?:jpe?g|png|gif)!Ui' , $content , $matches);


Prefix your regex with a negative assertion to filter out the common occurences:

 (?<!src=["\']|src=)

"Prefixing" means after your ! and before the https?://..

preg_match('!(?<!src=["\']|src=)http://.+\.(?:jpe?g|png|gif)!Ui' , $content , $matches);


You can try this one, that catches only the src tag and select the image url:

<img[^>]+src\s*=\s*['\"]([^'\"]+)['\"][^>]*>
0

精彩评论

暂无评论...
验证码 换一张
取 消