PCRE regex to Re2 Regex without negative lookahead

I am trying to use regex to filter emails from certain addresses in my office G Suite account email routing. In order to do so, I have created the following regex in order to do the following:

  • Accept all email address from a domain "domain.com"
  • Reject 2 of all those addresses from that domain.
  • In order to do so, I created the following regex that will complete the said function:

    ^(?!test|tes2)[A-Z0-9._%+-]+@domain.com$
    

    This one will reject both test@domain.com and tes2@domain.com and accept all other combinations from the said domain.

    However, G suite does not accept PCRE regex, so I currently cannot achieve this.

    Temporarily, I created the following Re2 regex to accept all email addresses from the said domain:

    (W|^)[w.+-]{0,25}@(domain).com(W|$)
    

    How can I expand this to allow the functionality intended since lookarounds are not allowed in re2 regex?


    Because this negative lookahead is fixed size, it's relatively straightforward to expand it like so. It does explode in complexity though; I've added comments and spacing for readability.

    ^
    ( # not /^t/
           [A-SU-Z0-9._%+-][A-Z0-9._%+-]*
    | # /^t/ but not /^te/
      t   ([A-DF-Z0-9._%+-][A-Z0-9._%+-]*)?
    | # /^te/ but not /^tes/
      te  ([A-RT-Z0-9._%+-][A-Z0-9._%+-]*)?
    | # /^tes/ but not /^tes[t2]/
      tes ([A-SU-Z013-9._%+-][A-Z0-9._%+-]*)?
    ) @domain.com $
    
    链接地址: http://www.djcxy.com/p/92646.html

    上一篇: 正则表达式匹配电子邮件,除了特定的电子邮件地址(es)

    下一篇: PCRE正则表达式为Re2正则表达式,没有负向视图