Regex - exclude domain

后端 未结 1 786
耶瑟儿~
耶瑟儿~ 2021-01-29 00:23

Lets say, I have domain

@abc.com.

I need to match the pattern if there are 3 or more external recipients.

For example: To:

相关标签:
1条回答
  • 2021-01-29 00:43

    You need to match:

    1. A "@"
    2. not followed by "abc."
    3. more characters until the next "@"
    4. (1), (2) and (3) repeated 3 times

    This expression will match a subject with 3 external recipients:

    (?:@(?!abc[.]).*?){3}
    

    DEMO


    Regular expression visualization

    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.

    0 讨论(0)
提交回复
热议问题