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