This must habe been asked a million times, but I can't find a solution to fit my needs.
I need to regex to check if a string contains an url, then get it. So I have this :
var regexToken = /(((ftp|https?):\/\/)[\-\w@:%_\+.~#?,&\/\/=]+)|((mailto:)?[_.\w-]+@([\w][\w\-]+\.)+[a-zA-Z]{2,3})/g;
while( (matchArray = regexToken.exec( source )) !== null )
{
var result = matchArray[0];
}
return result;
This can retrieve :
- http(s)|ftp://domain.com
- http(s)|ftp://www.domain.com
- http(s)|ftp://www.domain.com/with/path
But I need to modify that so it could also retrieve url that just begin with www :
- www.domain.com/with/path
How to do that ? I'm really noob with regex...