Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 preg_将所有www替换为http://www_Php_Regex_Preg Replace - Fatal编程技术网

PHP preg_将所有www替换为http://www

PHP preg_将所有www替换为http://www,php,regex,preg-replace,Php,Regex,Preg Replace,如何将一句话中出现的所有www替换为?条件是,如果匹配的www已具有http://前缀,则无需替换 为了更好地理解: <a href="www.test.com">test</a> should be <a href="http://www.test.com">test</a> <a href="http://www.test.com">test</a> also should be <a href="http://

如何将一句话中出现的所有www替换为?条件是,如果匹配的www已具有http://前缀,则无需替换

为了更好地理解:

<a href="www.test.com">test</a> should be <a href="http://www.test.com">test</a>

<a href="http://www.test.com">test</a> also should be <a href="http://www.test.com">test</a>
应该是
也应该是

您可以使用此正向前瞻
(?=www)
标记
www
之前的点,使用此反向前瞻
(?标记前面没有
http://
的点,并在该点插入
http://

(?<!http:\/\/)(?=www)
(?

另一种思考方式是,在“www”之前是否总是有空格?@ChrisForrence没有空格。@ChrisForrence问题已更新。@SujathanR:用你的