Reputation: 9
I am trying to build a regex that looks very similar to this, as for an example,
https://[a-zA-Z].google.com
which applied to the main domain.
I was wondering how do I make it work with including the main domain which is the google.com part?
Upvotes: 0
Views: 43
Reputation: 2222
I'd highly recommend you to read some basics on the regex topic and try out some builders, they are very helpful (my fav https://regex101.com/)
So in your case, first of all let's fix the original regex
https:\/\/[a-zA-Z]\.google\.com
[a-zA-Z]
group will match only a single symbol, so you need to add +
if you want there to be at least one character in the group or *
for any amount of characters (including 0)
https:\/\/[a-zA-Z]*\.google\.com
-
and numbers (sometimes even non-ascii characters, but let's not dig into it just yet)
https:\/\/[a-zA-Z-0-9]*\.google\.com
Now we're almost there.
You can add ?
after a symbol in regex to make it optional
https:\/\/[a-zA-Z-0-9]*\.?google\.com
will be your final regex
I hope that's clear. Don't hesitate to ask any questions :)
Upvotes: 2