$re = '/(https?://\S+)|:[\w+-]+:/m';
$str = ':smile: :thumbs_up: :+1: :-1:
but NOT if the colons are part of the url, like this URL for example: http://pdf.reuters.com/htmlnews/htmlnews.asp?i=43059c3bf0e37541&u=urn:newsml:reuters.com:20190417:nPn5XHnXBa
I was browsing and found this url :smile: http://pdf.reuters.com/htmlnews/htmlnews.asp?i=43059c3bf0e37541&u=urn:newsml:reuters.com:20190417:nPn5XHnXBa it\'s fantastic :smile::+1: Remember: don\'t forget to upvote!';
$subst = "\1";
$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