Gruber URL Regex tweak to capture "domain.com"

Posted by mootymoots on Stack Overflow See other posts from Stack Overflow or by mootymoots
Published on 2011-11-27T09:42:50Z Indexed on 2011/11/27 9:51 UTC
Read the original article Hit count: 267

Filed under:
|
|
|

I found an updated version of John Gruber's regex for url matching in this post by user GianPac, which states it's been adapted to recognize url without protocol or the www part:

(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}/?)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))))(?:(([^\s()<>]+|(([^\s()<>]+))))|[^\s`!()[]{};:'\".,<>?«»“”‘’]))

Whilst this works in most cases, I found it does not match "google.com". It does match "google.comm" and "google.co.uk", so this must be a small oversight.

The trouble is, I literally hate regex. It's the bane of my life. I just want to try and tweak this one more time to allow for "google.com" - can anyone throw me a pointer? I (think) it's something to do with this part of the code:

+[.][a-z]{2,4}/?)

?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about regex