org.sonar.l10n.py.rules.python.S6396.html Maven / Gradle / Ivy
Why is this an issue?
Curly brace quantifiers in regular expressions can be used to have a more fine-grained control over how many times the character or the
sub-expression preceeding them should occur. They can be used to match an expression exactly n times with {n}
, between n and m times with
{n,m}
, or at least n times with {n,}
. In some cases, using such a quantifier is superfluous for the semantic of the regular
expression, and it can be removed to improve readability. This rule raises an issue when one of the following quantifiers is encountered:
-
{1,1}
or {1}
: they match the expression exactly once. The same behavior can be achieved without the quantifier.
-
{0,0}
or {0}
: they match the expression zero times. The same behavior can be achieved by removing the expression.
Noncompliant code example
r"ab{1,1}c"
r"ab{1}c"
r"ab{0,0}c"
r"ab{0}c"
Compliant solution
r"abc"
r"ac"
© 2015 - 2024 Weber Informatics LLC | Privacy Policy