2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2022-02-02 16:59:48 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2022-02-02 16:59:48 +01:00
|
|
|
|
|
|
|
[source,java]
|
|
|
|
----
|
|
|
|
"(?:number)\\d{2}"
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2022-02-02 16:59:48 +01:00
|
|
|
|
|
|
|
[source,java]
|
|
|
|
----
|
|
|
|
"number\\d{2}" // it is anyway required
|
|
|
|
"(?:number)?\\d{2}" // it is in fact optional
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2022-02-02 16:59:48 +01:00
|
|
|
|
|
|
|
This rule does not report an issue if the non-capturing group is an alternation.
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
----
|
|
|
|
"(?:number|string)"
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../implementation.adoc[]
|