Help regular expression: End with a pattern followed by a/or string
I want a match pattern followed by/or the end of the string.
Requirements are as follows: two-segment domain name modified to three (increase www.)
Original string: http://a.com or http://a.com/or http://www.a.com/
To be replaced by: http://www.a.com
Http://k.a.com cannot be replaced by http://www.k.a.com
I wrote:
Preg_replace ('/(\/\/) ([^.\/]+\.[ ^.\/]+$)/I ', ' $1www.$2 ', ' http://weibo.com ');
Preg_replace ('/(\/\/) ([^.\/]+\.[ ^.\/]+\/)/I ', ' $1www.$2 ', ' http://weibo.com/');
Requires two substitutions, can you put the \/and $ together, similar to [A2]
------Solution--------------------
Preg_replace ('/(\/\/) ([^.\/]+\.[ ^.\/]+(?:\ /
------Solution--------------------
$))/I ', ' $1www.$2 ', ' http://weibo.com ');
------Solution--------------------
Give it a try
echo preg_replace ('/(\/\/) ([^.\/]+\.[ ^.\/]+)($
------Solution--------------------
\/) (. +)?/ie ', ' "$". " www. "." ". ("$4"?) "/"." $4 ":" ") ', ' http://weibo.com/aa ');