2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2021-10-29 09:54:32 +02:00
|
|
|
include::../description.adoc[]
|
2021-09-16 16:29:13 +02:00
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-09-16 16:29:13 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,php]
|
2021-09-16 16:29:13 +02:00
|
|
|
----
|
2021-09-17 18:43:00 +02:00
|
|
|
preg_replace("/start\w*?(end)?/", "x", "start123endstart456"); // Noncompliant. In contrast to what one would expect, the result is not "xx".
|
|
|
|
preg_match("/^\d*?$/", "123456789"); // Noncompliant. Matches the same as "/^\d*$/", but will backtrack in every position.
|
2021-09-16 16:29:13 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-09-16 16:29:13 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,php]
|
2021-09-16 16:29:13 +02:00
|
|
|
----
|
2021-09-17 18:43:00 +02:00
|
|
|
preg_replace("/start\w*?(end|$)/", "x", "start123endstart456"); // Result is "xx".
|
|
|
|
preg_match("/^\d*$/", "123456789");
|
2021-09-16 16:29:13 +02:00
|
|
|
----
|
|
|
|
|