HowTo Negate regex, inverse regex

How to regex match the opposite of what you’re searching (if that makes sense)

ps: happy new year.

This regex will match any string containing “MyString”

‘#MyString#’

This regex will be the opposite of the above, ie: matching any string that doesn’t contain “MyString”

‘#^((?!MyString).)*$#i’

Apparently regex is not good at doing these searches, so try to avoid. 

Leave a Reply

Your email address will not be published. Required fields are marked *