rspec/rules/S6019/python/rule.adoc
2022-02-04 16:28:24 +00:00

23 lines
506 B
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
[source,python]
----
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.
----
== Compliant Solution
[source,python]
----
re.replace(r"start\w*?(end|$)", "x", "start123endstart456") # Result is "xx"
re.match(r"^\d*$", "123456789")
----