disallow unnecessarily non-greedy quantifiers
- ⚙️ This rule is included in
- 🔧 The
--fixoption on the command line (opens new window) can automatically fix some of the problems reported by this rule.
# 📖 Rule Details
This rule reports lazy quantifiers that don't need to by lazy.
There are two reasons why a lazy quantifier doesn't have to lazy:
It's a constant quantifier (e.g.
The quantifier is effectively possessive (e.g.
Whether a quantifier (let's call it q) is effectively possessive depends on the expression after it (let's call it e). q is effectively possessive if q cannot accept the character accepted by e and e cannot accept the characters accepted by q.
In the example above, the character
aand the character
bdo not overlap. Therefore the quantifier
Since an effectively possessive quantifier cannot give up characters to the expression after it, it doesn't matter whether the quantifier greedy or lazy. However, greedy quantifiers should be preferred because they require less characters to write and are easier to visually parse.
# 🔧 Options
# 🚀 Version
This rule was introduced in eslint-plugin-regexp v0.10.0