I use this regex for URL’s:
var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/;
However, it seems to only be matching URL’s that are alone. If you add a URL to an already typed message, it won’t match:
Test message: www.google.com
Won’t match. How do I make it match URL’s no matter what’s included with them?
It’s because the
^character at the beginning of the expression means “match the beginning of the string” (in other words, what you have is a starts-with search). Remove that and it will match anywhere in the test string.