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:
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