21 lines
692 B
Plaintext
21 lines
692 B
Plaintext
![]() |
When a reluctant (or lazy) quantifier is followed by a pattern that can match the empty string or directly by the end of the regex, it will always match zero times for `+*?+` or one time for `++?+`. If a reluctant quantifier is followed directly by the end anchor (`+$+`), it behaves indistinguishably from a greedy quantifier while being less efficient.
|
||
|
|
||
|
This is likely a sign that the regex does not work as intended.
|
||
|
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
preg_match("/.*?x?/", $str); // Noncompliant, this will behave just like "x?"
|
||
|
preg_match("/.*?/", $str); // Noncompliant, replace with "."
|
||
|
----
|
||
|
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
preg_match("/.*?x/", $str);
|
||
|
preg_match("/.*/", $str);
|
||
|
----
|
||
|
|