rspec/rules/S5994/python/rule.adoc
2023-03-22 12:12:32 +01:00

23 lines
566 B
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
[source,python]
----
import re
pattern1 = re.compile(r"a++abc", re.DOTALL) # Noncompliant, the second 'a' never matches
pattern2 = re.compile(r"\d*+[02468]", re.DOTALL) # Noncompliant, the sub-pattern "[02468]" never matches
----
== Compliant Solution
[source,python]
----
import re
pattern1 = re.compile(r"aa++bc", re.DOTALL) # Compliant, for example it can match "aaaabc"
pattern2 = re.compile(r"\d*+(?<=[02468])", re.DOTALL) # Compliant, for example, it can match an even number like "1234"
----