1

Could you please help me to understand if RE2 allows to negate regular expressions (the same effect as "grep -v", i.e. "select everything that does not match a given expression")?

For example, I could match (positive match):

"[[:upper:]][[:upper:]][[:upper:]][[:digit:]]"

How do I select using RE2 everything that does not match the above expression (negative match)?

Thank you for your help!

S.V
  • 2,149
  • 2
  • 18
  • 41
  • possible duplicate of http://stackoverflow.com/questions/32844945/negate-match-for-word-in-the-beginning-of-string-in-re2-syntax/42797454#42797454 – mlg Mar 15 '17 at 03:46

1 Answers1

1

There is no negative lookbehind on RE2.

The best I've found is to match the negatives and discard them then search the remainder for what you want. Or depending on how you're coding this look for a condition of not true or not equals the RE2 negative expression AND a true or equals of the RE2 positive expression.

  • if you have any example for omitting the match, please do share here to help out! that would be really helpful – CdVr Jul 22 '20 at 14:39
  • This depends on what language you're using. In Big Query SQL is can be as easy as just: `WHEN REGEXP_CONTAINS(section, r"(.*(traffic).*)") AND NOT REGEXP_CONTAINS(section, r"(.*trafficing.*)") ` – Cory Brickner Jul 27 '20 at 15:18