Regular expression for help: the regular expression ends with a pattern or string & nbsp; I want a matching pattern followed by or ended with a string. The requirement is as follows: change the two domain names to three (add www .) original string: a.com & nbsp; or & nbsp; http: help regular expression: end with a/or string after a pattern
I want to end a matching pattern with a/or string.
The requirement is as follows: change the two domain names to three (add www .)
Original string: http://a.com or http://a.com/or http://www.a.com/
Replace with: http://www.a.com
Http://k.a.com cannot be replaced with http://www.k.a.com
I wrote:
Preg_replace ('/(\/) ([^. \/] + \. [^. \/] + $)/I ',' $ 1www. $2 ', 'http: // weibo.com ');
Preg_replace ('/(\/) ([^. \/] + \. [^. \/] + \/)/I ',' $ 1www. $2 ', 'http: // weibo.com /');
It needs to be replaced twice. can I put \/and $ together, similar to [a2]?
------ Solution --------------------
Preg_replace ('/(\/) ([^. \/] + \. [^. \/] + (? :\/
------ Solution --------------------
$)/I ',' $ 1www. $ 2', 'http: // weibo.com ');
------ Solution --------------------
Try
Echo preg_replace ('/(\/) ([^. \/] + \. [^. \/] +) ($
------ Solution --------------------
\/) (. + )? /Ie ',' "$1". "www.". "$2". ("$4 "? "/". "$4": "") ', 'http: // weibo.com/aa ');