2023-08-04 16:12:40 +02:00
|
|
|
:lookahead: php/lookahead.adoc
|
|
|
|
|
|
|
|
This rule raises an issue when a regex lookahead contradicts the rest of the regex.
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2021-09-27 17:56:44 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
2023-08-04 16:12:40 +02:00
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
2021-09-27 17:56:44 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,php]
|
2021-09-27 17:56:44 +02:00
|
|
|
----
|
|
|
|
preg_match("/(?=a)b/", $str); // Noncompliant, the same character can't be equal to 'a' and 'b' at the same time
|
|
|
|
----
|
|
|
|
|
2023-08-04 16:12:40 +02:00
|
|
|
==== Compliant solution
|
2021-09-27 17:56:44 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,php]
|
2021-09-27 17:56:44 +02:00
|
|
|
----
|
|
|
|
preg_match("/(?<=a)b/", $str);
|
|
|
|
preg_match("/a(?=b)/", $str);
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|