An empty character class in a regular expression does not match anything and may indicate missing code.

Omit the empty character class. If the whole regular expression would become empty, use /(?:)/ to express a deliberately empty regular expression.

In the following example, the programmer presumably meant to write a regular expression that matches an opening square bracket or curly brace, followed by one or more letters or digits, followed by a closing square bracket or curly brace. However, they forgot to escape the closing square bracket with a backslash, leading to an empty character class. The resulting regular expression is malformed and could be interpreted differently on different platforms.

To fix this problem, the regular expression should be rewritten to /[[{]\w+[\]}]/.

  • Mozilla Developer Network: JavaScript Regular Expressions.