Why is this an issue?
Character classes in regular expressions will match any of the characters enclosed in the square brackets (
[abc] will match
You can specify a range of characters using a hyphen (
-). If the hyphen appears as the first or last character, it will be matched as
a literal hyphen.
An empty character class (
) will not match any character because the set of matching characters is empty. So the regular expression
will not work as you intended.
/^foo/.test(str); // Noncompliant: always returns "false"
Use a non-empty character class or a different regular expression pattern that achieves the desired result.