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.
Examples
Section titled “Examples”Zero Minimum (Will Match Empty String)
Section titled “Zero Minimum (Will Match Empty String)”const const pattern: RegExp
pattern = /a*?/;const const pattern: RegExp
pattern = /a*?b/;One Minimum (Will Match Exactly Once)
Section titled “One Minimum (Will Match Exactly Once)”const const pattern: RegExp
pattern = /a+?/;const const pattern: RegExp
pattern = /a+?b/;Range Minimum (Will Match Minimum Times)
Section titled “Range Minimum (Will Match Minimum Times)”const const pattern: RegExp
pattern = /a{3,7}?/;const const pattern: RegExp
pattern = /a{3,7}?b/;Inside Groups
Section titled “Inside Groups”const const pattern: RegExp
pattern = /(?:a|bc+?)/;const const pattern: RegExp
pattern = /(?:a|bc+?)d/;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-lazy-ends
Made with ❤️🔥 around the world by
the Flint team and contributors.