Please help me improve my Regex to determine External links other than my own website. E.g- My Website is : myweb.com. And if I also issue subdomains like abc.myweb.com. I want to find link other than these two patterns, So I can prevent External Links.
$string = 'www.client.com, www.client.co.in, www.myweb.com, www.abc.myweb.com';
$string = preg_replace('/[https?://]?(www\.)?(?!myweb.com)[^\s/]+(?:/[^\s/]+)*/?/s', '*', $string);
var_dump($string);
This GIST might be useful to you taken from this Daring Fireball post
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))