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
"/ab{1,1}c/"
"/ab{1}c/"
"/ab{0,0}c/"
"/ab{0}c/"
Compliant solution
"/abc/"
"/ac/"