2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2022-02-02 16:59:48 +01:00
|
|
|
include::../description.adoc[]
|
2022-01-28 12:40:19 +00:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2022-01-28 12:40:19 +00:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,php]
|
2022-01-28 12:40:19 +00:00
|
|
|
----
|
|
|
|
"(?:number)\d{2}"
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2022-01-28 12:40:19 +00:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,php]
|
2022-01-28 12:40:19 +00:00
|
|
|
----
|
|
|
|
"number\d{2}"
|
|
|
|
"(?:number)?\d{2}"
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2022-01-28 12:40:19 +00:00
|
|
|
|
2022-03-24 17:23:48 +01:00
|
|
|
This rule does not report an issue if the non-capturing group is an alternation.
|
|
|
|
|
|
|
|
[source,php]
|
2022-01-28 12:40:19 +00:00
|
|
|
----
|
|
|
|
"(?:number|string)"
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Resources
|
2022-01-28 12:40:19 +00:00
|
|
|
|
|
|
|
https://www.php.net/manual/en/regexp.reference.subpatterns.php[Subpatterns] - PHP Documentation
|
|
|
|
|
2022-03-24 17:23:48 +01:00
|
|
|
include::../implementation.adoc[]
|