regexUnusedQuantifiers
Reports quantifiers that match exactly once, making them unnecessary.
✅ This rule is included in the ts logical presets.
Reports quantifiers that match exactly once ({1} or {1,1}), which are unnecessary because the element already matches exactly once by default.
Examples
Section titled “Examples”Exact Match of One
Section titled “Exact Match of One”const pattern = /a{1}/;const pattern = /a/;Range of One to One
Section titled “Range of One to One”const pattern = /a{1,1}/;const pattern = /a/;Groups with Useless Quantifiers
Section titled “Groups with Useless Quantifiers”const pattern = /(ab){1}/;const pattern = /(ab)/;Character Classes
Section titled “Character Classes”const pattern = /[a-z]{1}/;const pattern = /[a-z]/;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally use {1} quantifiers for documentation or consistency purposes, 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/no-useless-quantifier
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.