I’ve got this regex pattern from WMD showdown.js file.
/<((https?|ftp|dict):[^'">\s]+)>/gi
and the code is:
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");
But when I set text to http://www.google.com, it does not anchor it, it returns the original text value as is (http://www.google.com).
P.S: I’ve tested it with RegexPal and it does not match.
As long as you know your url’s start with http:// or https:// or whatever you can use:
The expression will match till it encounters a character not allowed in the URL i.e. is not
A-Za-z\.\-. It will not however detect anything of the formgoogle.comor anything that comes after the domain name like parameters or sub directory paths etc. If that is your requirement that you can simply choose to terminate the terminating condition as you have above in your regex.I know it seems pointless but it may be useful if you want the display name to be something abbreviated rather than the whole url in case of complex urls.