Skip to content

regexp/no-useless-quantifier

💼 This rule is enabled in the following configs: 🟢 flat/recommended, 🔵 recommended.

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

disallow quantifiers that can be removed

📖 Rule Details

This rule reports quantifiers that can trivially be removed without affecting the pattern.

This rule only fixes constant-one quantifiers (e.g. a{1}). All other reported useless quantifiers hint at programmer oversight or fundamental problems with the pattern.

Examples:

  • a{1}

    It's clear that the {1} quantifier can be removed.

  • (?:a+b*|c*)?

    It might not very obvious that the ? quantifier can be removed. Without this quantifier, that pattern can still match the empty string by choosing 0 many cs in the c* alternative.

  • (?:\b)+

    The + quantifier can be removed because its quantified element doesn't consume characters.

Now loading...

🔧 Options

Nothing.

🚀 Version

This rule was introduced in eslint-plugin-regexp v0.10.0

🔍 Implementation