$re = '/(http\:|ftp\:|https\:)?(\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+)[\w.,@?^=%&:\/~+#-()].*[\w@?^=%&\/~+#-]?)(?=\s|$)/imU';
$str = 'https://en.wikipedia.org/wiki/Salt_(2010_film)
https://en.wikipedia.org/wiki/Salt_2010_film
https://en.wikipedia.org/wiki/Salt-2010-film
HTTPS://en.wikipedia.org/wiki/Salt-2010-film
//en.wikipedia.org/wiki/Salt_2010_film
https://en.wikipedia.org/wiki/Salt_2010_film?cat=1
https://en.wikipedia.org/wiki/Salt_2010_film#anchor
https://en.wikipedia.org/wiki/Salt_(2010_film)?cat=2
This is a sentence that has a link in it. https://en.wikipedia.org/wiki/Salt_(2010_film)?cat=3 This regex allows me to create an HTML anchor tag around it.';
$subst = "<a href=\"${1}${2}${3}\" target=\"_blank\">${1}${2}${3}</a>";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php