正则表达式 - 排除域 [英] Regex - exclude domain
问题描述
假设,我有域名
@abc.com.
如果有 3 个或更多外部收件人,我需要匹配模式.
例如:致:
<块引用>user1@abc.com;external@contoso.com;user2@abc.com;user3@abc.com;user4@abc.com;user5@abc.com;external2@contoso.com;test@google.com
我已经拥有的正则表达式如下所示:
到:(.*@[^a][^b][^c][^.][^c][^o][^m].*){3,}
它有点工作,但看起来很讨厌.也许以某种方式实现这个?^((?!@abc.com).){3,}
谢谢!对我很有帮助
您需要匹配:
- A
"@"
- 后面没有
"abc."
- 直到下一个
"@"
的更多字符 - (1)、(2) 和 (3) 重复 3 次
此表达式将匹配具有 3 个外部收件人的主题:
(?:@(?!abc[.]).*?){3}
(?!abc[.])代码> 以检查您的域后面没有跟随它.
.*?
用于在不同的 @
s 之间使用字符.
您也可以将 abc[.]
更改为 abc[.]com(?:[; ]|$)
或您的真实域名.
Lets say, I have domain
@abc.com.
I need to match the pattern if there are 3 or more external recipients.
For example: To:
user1@abc.com; external@contoso.com; user2@abc.com; user3@abc.com; user4@abc.com; user5@abc.com; external2@contoso.com; test@google.com
The regex I already have looks like that:
To:(.*@[^a][^b][^c][^.][^c][^o][^m].*){3,}
Its kinda working, but looking nasty.
Maybe somehow implement this? ^((?!@abc.com).){3,}
Thank you! It would help me a lot
You need to match:
- A
"@"
- not followed by
"abc."
- more characters until the next
"@"
- (1), (2) and (3) repeated 3 times
This expression will match a subject with 3 external recipients:
(?:@(?!abc[.]).*?){3}
It uses the negative lookahead (?!abc[.])
to check it's not followed by your domain. The .*?
is there to comsume the chars between different @
s.
You may as well change abc[.]
to abc[.]com(?:[; ]|$)
or your real domain.
这篇关于正则表达式 - 排除域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!