Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
带有regex preg_replace的php标记_Php_Preg Replace - Fatal编程技术网

带有regex preg_replace的php标记

带有regex preg_replace的php标记,php,preg-replace,Php,Preg Replace,我有一个url,比如说: 图像和标签 <img f="/example2"></img> <img f="example3"></img> <img f="http://example4.com"></img> <img f="https://example5.com"></img> 因此,如果我在上面的标记中使用此代码,输出将是: $regex = "-(src\s*=\s*['\"])(((?!

我有一个url,比如说: 图像和标签

<img f="/example2"></img>
<img f="example3"></img>
<img f="http://example4.com"></img>
<img f="https://example5.com"></img>
因此,如果我在上面的标记中使用此代码,输出将是:

$regex = "-(src\s*=\s*['\"])(((?!'|\"|http://|https://).)*)(['\"])-i";

不确定我是否在跟踪您,但是,
f=“(?!https?:/)/?(.*)”
呢?我在regex中使用了
f
,因为这就是您的示例所使用的。这不是我要找的,假设我想要如果src在开始时没有/a,那么我们将在开始时添加url?
<img f="https://stackoverflow.com/example1//example2></img>
<img f="https://stackoverflow.com/example1/example3></img>
<img f="http://example4.com/"></img>
<img f="https://example5.com/"></img>