regexStarQuantifiers
Reports quantifiers
{0,}in regular expressions that should use*instead.
✅ This rule is included in the ts stylisticStrict presets.
Reports quantifiers using {0,} in regular expressions and suggests using the more concise * quantifier instead.
Both forms are semantically equivalent (matching zero or more of the preceding element), but * is the idiomatic form.
Examples
Section titled “Examples”Greedy Quantifier
Section titled “Greedy Quantifier”const const pattern: RegExp
pattern = /a{0,}/;const const pattern: RegExp
pattern = /a*/;Lazy Quantifier
Section titled “Lazy Quantifier”const const pattern: RegExp
pattern = /a{0,}?/;const const pattern: RegExp
pattern = /a*?/;Groups
Section titled “Groups”const const pattern: RegExp
pattern = /(ab){0,}/;const const pattern: RegExp
pattern = /(ab)*/;RegExp Constructor
Section titled “RegExp Constructor”const const pattern: RegExp
pattern = new var RegExp: RegExpConstructornew (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp("a{0,}");const const pattern: RegExp
pattern = new var RegExp: RegExpConstructornew (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
RegExp("a*");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your project has a style guide that prefers the explicit {0,} syntax for clarity, or if you are programmatically generating regular expressions where {0,} is easier to produce, you might want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/prefer-star-quantifier
Made with ❤️🔥 around the world by
the Flint team and contributors.