Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在正则表达式模式中进行非常简单的编辑_Php_Regex - Fatal编程技术网

Php 在正则表达式模式中进行非常简单的编辑

Php 在正则表达式模式中进行非常简单的编辑,php,regex,Php,Regex,如何将这个正则表达式转换为仅在src=*中搜索,而不是所有以http开头并以jpg、png、gif结尾的链接?此外,我想得到的https图像。 谢谢大家! preg_match('!http://.+\.(?:jpe?g|png|gif)!Ui' , $content , $matches); 您可以尝试此方法,它只捕获src标记并选择图像url: <img[^>]+src\s*=\s*['\"]([^'\"]+)['\"][^>]*> 在正则表达式前面加上否定断言以

如何将这个正则表达式转换为仅在src=*中搜索,而不是所有以http开头并以jpg、png、gif结尾的链接?此外,我想得到的https图像。 谢谢大家!

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

您可以尝试此方法,它只捕获src标记并选择图像url:

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

在正则表达式前面加上否定断言以过滤常见事件:

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

相关的,为了喜剧的价值。。。嗨,谢谢你提供的信息,但我没有问你this@middaparka字体这不仅仅是喜剧。。。它是truth@Tomalak最好的喜剧往往是以事实为基础的-你好!$模式=]*>;preg_match_all$pattern、$content、$filtered;我得到了这个错误:警告:preg_match_all[function.preg match all]:未知修饰符']'@Punkis:您需要用分隔符包装正则表达式。您好。preg_match_all’?我不会在评论中提供辅导。是的,我可以。作为对策,我要求您回顾您的/过去的/问题,并利用▲ 在评论中提供额外帮助的问题上向上投票箭头。当你达到投票限制时再来。
preg_match('!(?<!src=["\']|src=)http://.+\.(?:jpe?g|png|gif)!Ui' , $content , $matches);