Skip to content

regexRepeatQuantifiers

Reports consecutive identical elements in regular expressions that should use quantifiers.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Matching multiple consecutive characters in a regular expression can be done either by writing out that character repeatedly or using a quantifier. Quantifiers keep the regex shorter and harder to miscount, and they make it obvious how many times a part repeats without visually scanning a long run of characters. For example, writing a{5} is more concise and readable than aaaaa.

This rule reports runs of five or more identical elements in regular expressions and suggests replacing them with quantifiers.

const pattern = /aaaaa/;
const pattern = /\d\d\d\d\d/;
const pattern = /[a-z][a-z][a-z][a-z][a-z]/;
const pattern = /...../;
const pattern = new RegExp("aaaaa");

This rule is not configurable.

If your project has a style guide that prefers explicit repetition for clarity, or if you are programmatically generating regular expressions where repetition is easier to produce, you might want to disable this rule.