I use the following regexp in a php function to replace URLs with proper HTML links:
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
But when $s has for value a string like
<li>http://www.link.com/something.pdf</li>
the function returns
<li><a href="http://www.link.com/something.pdf</li">http://www.link.com/something.pdf</li></a></li>
Does anyone know how to modify the regexp to get the intended string, i.e.
<li><a href="http://www.link.com/something.pdf">http://www.link.com/something.pdf</a></li> ?
without excluding from the replacement substrings of the URL introduced by '%', '?' or '&' ?