Negations in Regex

Writing by on Friday, 26 of May , 2017 at 6:43 pm

If you are in the situations where you know what NOT to look for, but everything else is considered a match, then you need to negate the pattern and use something like this as explained on this permonks thread.

^(?:(?!PATTERN).)*$
^(?:(?!nope|no|not|never|negate|negation).)*$

Here’s an example in Sublime Text.

Leave a comment

Category: Uncategorized

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.