Disallow unnecessary quantifiers.
configuration in plugin:clean-regex/recommended
: "warn"
Unnecessary quantifiers are quantifiers which can be removed without changing the meaning of the pattern.
A trivial example is: a{1}
Obviously, the quantifier can be removed.
This is the only auto-fixable unnecessary quantifier. All other unnecessary quantifiers hint at programmer oversight or fundamental problems with the pattern.
A not-so-trivial example is: (?:a+b*|c*)?
It's not very obvious that the
?
quantifier can be removed. Without this quantifier, that pattern can still
match the empty string by choosing 0 many c
in the c*
alternative.
Other examples include (?:\b|(?=%))+
and (?:|(?:)){5,9}
.