2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-07-20 11:17:29 +02:00
Character classes in regular expressions will match any of the characters enclosed in the square brackets (`[abc]` will match `a`, `b` or `c`).
2023-03-08 15:13:49 +01:00
2023-07-20 11:17:29 +02:00
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.
[source,javascript,diff-id=1,diff-type=noncompliant]
2023-03-08 15:13:49 +01:00
----
2023-07-20 11:17:29 +02:00
/^foo[]/.test(str); // Noncompliant: always returns "false"
2023-03-08 15:13:49 +01:00
----
2023-07-20 11:17:29 +02:00
Use a non-empty character class or a different regular expression pattern that achieves the desired result.
[source,javascript,diff-id=1,diff-type=compliant]
----
/^foo/.test(str);
----
2023-03-08 15:13:49 +01:00
2023-06-15 15:56:08 +01:00
== Resources
=== Documentation
2023-10-19 11:46:59 +02:00
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes[Character classes]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions[Regular expressions]
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-03-08 15:13:49 +01:00
=== Message
Rework this empty character class that doesn't match anything.
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2023-06-22 10:38:01 +02:00
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]