How to match all email addresses at a specific domain using regex?
I need help on finding a regex expression that will match email addresses of only a specific domain
As in any .*@testdomain.com
And also the opposite any thing other than .*@testdomain.com
Ay
I propose an expression very simple:
^[A-Za-z0-9._%+-]+@testdomain.com$
and for the negative check:
^[A-Za-z0-9._%+-]+@(?!testdomain.com)[A-Za-z0-9.-]+.[A-Za-z]{2,4}$
I hope could work for you
grep -oE '( |^)[^ ]*@testdomain.com( |$)' file.txt
-o Returns only the matched string
The above will give all email id's of testdomain in file.txt.
For my particular scenario, I needed this variation:
'^[A-Za-z0-9._%+-]+@' + email_domain + '$'
this would match an email_domain from a list of email_domains: ['example1.com', 'example2.co.uk'] and I was running through the list, matching each one against a list of email addresses.
链接地址: http://www.djcxy.com/p/92644.html