JavaScript Regular Expression Square Bracket Negation

In JavaScript Regular Expressions the caret (^) can be used in square brackets as a negation character.

/[^abc]/ – would match for any characters that are not a, b or c.

/[^hb]at/ – would match for cat but not for hat or bat.

Leave a Reply