I just made a regex pattern for replace links to HTML anchor tags, this is it:
~((http\:\/\/|https\:\/\/)([^ ]+)) ~
The reason why I ask this, is because I just finished this regex recently and made a few tests with some links, it works great but I want to be sure that there is no bugs with this pattern (I'm a regex newie) and maybe a regex expert could tell his opinion and / or suggestion.
By the way, if you're figuring out the space at the end, you may think it will not work if the string doesn't ends with a space, but my trick is to add that space to the string before the replacement and then remove it again once the stuff is done.
PD:
I don't take care of the link's validation itself, I just want to search for the strings that starts with http:// and ends with a space, nothing else, since link validation is a bit complicated.
EDIT:
Some of my code:
<?php
$patron = "~(https?:\/\/[^\s]+) ~";
//$patron = "~((http\:\/\/|https\:\/\/)([^ ]+)) ~";
$reemplazar = '<a href="$1">$1</a> ';
$cadena = "https://www.youtube.com/watch?v=7it5wioGixA ";
echo preg_replace($patron, $reemplazar, $cadena);
?>
FILTER_VALIDATE_URLoption.