Reputation: 22275
I'm trying to come up with a regex that would catch a TLD in a group of subdomains. So I have this:
/\.?google\.com$/i
That should do the following matches:
sgoogle.com -- no match
google.com -- match
maps.google.com -- match
job_s.map.google.com -- match
place.google.com.eu -- no match
This works, except for the first one, i.e. sgoogle.com
that it matches as well, which it shouldn't.
So I'm curious, is there a way to specify where I do \.?
to match either a dot or the beginning of string?
Upvotes: 0
Views: 50
Reputation: 51330
You're almost there. Literally, your requirement would be:
(?:^|\.)google\.com$
But depending on your needs, this could be better (or not, you tell me):
\bgoogle\.com$
The \b
means word boundary.
Upvotes: 5