Php 如何预先替换图像的所有链接(使用和*不使用*https?)

Php 如何预先替换图像的所有链接(使用和*不使用*https?),php,regex,Php,Regex,我正在使用,我看到了这个 我试图不匹配字符串 我需要用字符串替换所有出现的图像链接 。 所以我想用(https?:\/\/)?\S*(jpg | png | jpeg | bmp | gif)或使用相同的东西,但不使用前面的(https?:/) 以便: Hi there this is an image link https://facebook.com/images/2323.jpg and this one is too mysite.org/1.png 将变成: Hi there thi

我正在使用,我看到了这个

我试图不匹配字符串

我需要用字符串替换所有出现的图像链接
。 所以我想用
(https?:\/\/)?\S*(jpg | png | jpeg | bmp | gif)
使用相同的东西,但不使用前面的
(https?:/)

以便:

Hi there this is an image link https://facebook.com/images/2323.jpg
and this one is too mysite.org/1.png
将变成:

Hi there this is an image link
<<IMAGE:https://facebook.com/images/2323.jpg>> and this one is too
<<IMAGE:mysite.org/1.png>>
您好,这是一个图像链接
这一个也是

我想你想要这个

$str = 'Hi there this is an image link https://facebook.com/images/2323.jpg
and this one is too mysite.org/1.png';

$regex = '/((https?:\/\/)?\S*(jpg|png|jpeg|bmp|gif))/';

$str = preg_replace($regex, '<<IMAGE:$1>>', $str);
echo $str;
$str='您好,这是一个图像链接https://facebook.com/images/2323.jpg
这一个是太mysite.org/1.png';
$regex='/((https?:\/\/)?\S*(jpg | png | jpeg | bmp | gif))/';
$str=preg_replace($regex,,$str);
echo$str;
输出

Hi there this is an image link <<IMAGE:https://facebook.com/images/2323.jpg>>
and this one is too <<IMAGE:mysite.org/1.png>>
您好,这是一个图像链接
这一个也是

@阿尔瓦罗·G·维卡里奥还是带“不”的ing(https?)你说“试图不匹配字符串”是什么意思?除此之外,已经有了。这是一个文本块,不是一个需要解析的链接。对不起,我发布了错误的链接,后来删除了评论,并用正确的链接添加了一个新的评论。你到底想要什么输出?这看起来不错,但它匹配dsfhttps://facebook.com/images/2323.jpg 这也是一个无效的链接!