# regexp/no-useless-quantifier

disallow quantifiers that can be removed

  • ⚙️ This rule is included in "plugin:regexp/recommended".
  • 🔧 The --fix option on the command line (opens new window) can automatically fix some of the problems reported by this rule.

# 📖 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