I need a simple javascript regular expression to match urls in a string. This is what I have at the moment:
/(https?://)?[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9].[^s]{2,}/gi
This works 99% of the time for any url that contains 3 or more characters, for example all of these work:
abc.com
abcd.com
but I can’t get it to work for a url with 2 characters:
ab.com
ow.ly
I’m using the match method like this:
let regex = /(https?://)?[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9].[^s]{2,}/gi
let matches = "http://ab.com".match(regex)
Thanks