https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)? PHP Example: Automatically link URL's inside text. $text = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '$1', $text);