JavaScript

JavaScript

Made by DeepSource

Found empty character classes in regular expressions JS-0010

Bug risk
Major

Empty character classes in regular expressions do not match anything. This is generally the result of a typo.

Bad Practice

/^abc[]/.test("abcdefg"); // false
"abcdefg".match(/^abc[]/); // null

Recommended

/^abc/.test("abcdefg"); // true
"abcdefg".match(/^abc/); // ["abc"]

/^abc[a-z]/.test("abcdefg"); // true
"abcdefg".match(/^abc[a-z]/); // ["abcd"]