How can I “inverse match” with regex?

(?!Andrea).{6}

Assuming your regexp engine supports negative lookaheads…

…or maybe you’d prefer to use [A-Za-z]{6} in place of .{6}

Note that lookaheads and lookbehinds are generally not the right way to “inverse” a regular expression match. Regexps aren’t really set up for doing negative matching; they leave that to whatever language you are using them with.

Leave a Comment