preg_replace help

We have a preg_replace call to take links such as

and convert them into html links. This works well but we are having a problem with it. If the link has a trailing . or ) it is added to the link:

http://www.site.com.
(http://www.site.com)

I have a very difficult time with regex and I am hoping someone can point me into the right direction to ignore the trailing . or ) if it exists

Here is the code:



$stext = preg_replace("/(?<!href=\\")((http|ftp)+(s)?:\\/\\/[^<>\\s]+)/i", "<a href=\\"\\\\0\\" target=\\"_blank\\">\\\\0</a>",$stext);


In the part [^<>\s] add in the end bracket, so [^<>\s)]. Because the bracket is a special character (for matches e.g. (.*) ) you may need to escape it as [^<>\s\)].

Here are a collection of link-based regular expressions that you can use.

RegExLib link patterns

Have a scan through them and check the matches/non-matches section of each one to find one that most-closely performs what you need it to do.