I am having a hard time writing this regular expression.
Basically I need to block email delivery if the message recipient envelope contains an unapproved domain. My internet mail gateway (Brightmail) allows to create rules where I can specify a condition using Match/DoesNotMatch a regular expression.
For example I need only allow mail to yahoo.com, hotmail.com, and gmail.com.
If someone sends a message to some other domain, the message should be blocked.
If someone sends a message to yahoo.com AND some other domain, the message should be blocked
If someon开发者_StackOverflow中文版e sends a message to yahoo.com, the message should be allowed.
Is this possible?
If someone sends a message to yahoo.com and hotmail.com, the message should be allowed.
I am not a total noob with regular expression, but this one has me stumped.
That sounds like its possible. It would be a token find where you have a series of OR operators between tokens.
I don't know if you have ever used this site, but it is a GODSEND when I am developing regex queries.
http://regexpal.com/
I played with RegexPal and picked a combination that will satisfy my needs.
Basically this will match the substrings before the @ character for only those strings that ARE NOT the listed ones.
(?!(.@yahoo.com|.@hotmail.com|.@gmail.com)).@
or even this will work
(?!(.@yahoo.com|.@hotmail.com|.*@gmail.com))@
or this
@(?!(.@yahoo.com|.@hotmail.com|.*@gmail.com))
or even better
@(?!(.*(yahoo|hotmail|gmail).com))
The last one will just highlight the @ sign in the domain name strings that do Not belong.
精彩评论