# regexp/optimal-quantifier-concatenation

require optimal quantifiers for concatenated quantifiers

  • ⚙️ 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

If two quantified characters, character classes, or characters are concatenated, the quantifiers can be optimized if either of the characters elements is a subset of the other.

Let's take \d+\w+ as an example.
This can be optimized to the equivalent pattern \d\w+. Not only is the optimized pattern simpler, it is also faster because the first pattern might take up to O(n^2) steps to fail while the optimized pattern will fail after at most O(n) steps. Generally, the optimized pattern will take less backtracking steps to fail.

Choosing optimal quantifiers does not only make your patterns simpler but also faster and most robust against ReDoS attacks.

Now loading...

# 🔧 Options


# 🚀 Version

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

# 🔍 Implementation

Last Updated: 6/25/2022, 12:32:38 PM