I want to match a URL link in a wall post and replace this link with anchor tag. For this I use the regular expression below.
I would like the match four types of URL:
http://example.comhttps://example.comwww.example.comexample.com
preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@',
'<a href="$1">$1</a>', $subject);
This expression matches only first two types of URL.
If I use this expression for matching a URL pattern,
'@(www?([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', it only matches the third type of URL pattern.
How can I match all four typeS of URL patternS with a single regular expression?