2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2022-02-02 14:02:12 +01:00
|
|
|
include::../description.adoc[]
|
2021-07-20 15:52:54 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-07-20 15:52:54 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2021-07-20 15:52:54 +02:00
|
|
|
----
|
|
|
|
const dateRegex = /^(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\d\d(?:)$/; // Noncompliant, useless group at the end
|
|
|
|
const methodCallRegex = /foo()/; // Noncompliant, will match only 'foo'
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-07-20 15:52:54 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2021-07-20 15:52:54 +02:00
|
|
|
----
|
|
|
|
const dateRegex = /^(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\d\d$/;
|
|
|
|
const methodCallRegex = /foo\(\)/; // OK, matches 'foo()'
|
|
|
|
----
|