开发者

preg_match & regex fail to catch full url with filename "a.jpg_x.jpg"

开发者 https://www.devze.com 2023-01-02 15:36 出处:网络
I use in my code : preg_match( \'!http://[^?#]+\\.(?:jpe?g|png|gif)!Ui\' , $str[1], $results ); It work in most cases except:

I use in my code :

preg_match( '!http://[^?#]+\.(?:jpe?g|png|gif)!Ui' , $str[1], $results );

It work in most cases except:

src='http://www.domain.com/Pic/folder1/folder2/a.jpg_x.jpg' alt=

I get:

......older2/a.jpg

I need:

.....older2/a.jpg_x.jpg
开发者_运维问答

any ideas?

Thanks in advance


$str = "src='http://www.domain.com/Pic/folder1/folder2/a.jpg_x.jpg' alt=";
preg_match("!http://[^?#']+\.(?:jpe?g|png|gif)!i", $str, $results );
var_dump($results);


I believe you need the end of expression character "$"

eg. preg_match( '!http://[^?#]+.(?:jpe?g|png|gif)$!Ui' , $str[1], $results );

NOTE: This is completely untested. Sorry I'm posting from my phone so I cant test.

0

精彩评论

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