I have a regex that extracts typed URL's from a string (a description text that could include typed URL's) and converts them to href's. This all works fine except for the fact that when a URL is typed and it's last character is a "," of ")" it also takes this character as part of the URL. How could I prevent this?
Example text:
Hi this is my beautiful message which contains a link (see www.website.com) and some more info.
My regex reads the URL but also takes the last character ")" when it creates the href, resulting in a bad link.
My Regex:
preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $text);