Skip to content

regexEmptyLazyQuantifiers

Reports lazy quantifiers at the end of regular expressions.

✅ This rule is included in the ts logical presets.

Reports lazy quantifiers at the end of regular expressions that will never match more than their minimum. Lazy quantifiers like *?, +?, or {n,m}? at the end of a pattern are useless because there is nothing after them to require a larger match.

const pattern = /a*?/;
const pattern = /a+?/;
const pattern = /a{3,7}?/;
const pattern = /(?:a|bc+?)/;

This rule is not configurable.

If you tend to use patterns as a partials (e.g., to combine with other patterns via string concatenation), you might need to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.