I have a Regex to match a subdomains of a web page like below
"^https://[^/?]+\\.(sub1|sub2\\.)domain\\.com"
What would be the regex to accept any sub domain of domain.com.
Edit:
My question was incomplete, my regex was to accept only
https:[any number of sub domain s ].sub1domain.com
or
https://[any number of sub domain s ].sub2domain.com
Sorry for posting incomplete question.
This one should suit your needs:
https?://([a-z0-9]+[.])*sub[12]domain[.]com
I'm assuming that don't want the subdomains to differ simply by a number. Use this regex:
(^https:\/\/(?:[\w\-\_]+\.)+(?:subdomain1|subdomain2).com)
The single capture group is the full URL. Simply replace subdomain1 and subdomain2 with your actual subdomains.
I tested this on regex101.com
You would use
"^https://[^/?]+\\.([^.]+)\\.domain\\.com"
which boils down to matching
"[^.]+"
for any subdomain. will match only the last part of the subdomain (www.xxx.domain.com will capture "xxx" in group 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With