I am looking to match all email addresses from a specific domain.
Any email coming from example.com
or foo.example.com
should match, everything else should be rejected. To do this, I could do some basic string matching to check if the given string ends with, or contains, example.com
which would work fine but it also means that something like fooexample.com
will pass.
Hence, based on the above requirements, I started working on a pattern that would pass the domain and its sub-domain. I was able to come up with the following regex pattern:
`/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.example.com\b/i`
This only matched subdomains, but I have seen the pattern at "How to match all email addresses at a specific domain using regex?" which handles the main domain.
Is there a way to combine these two into something that works for any address from example.com.