Negate match in RE2 syntax?

Richard picture Richard · Jan 28, 2015 · Viewed 8.8k times · Source

How can I write a regex in RE2 for "match strings not starting with 4 or 5"?

In PCRE I'd use ^(?!4) but RE2 doesn't support that syntax.

Answer

anubhava picture anubhava · Jan 28, 2015

You can use this regex:

^[^45]

^ matches start and [^45] matches anything but 4 or 5 at start.