Pattern: Unnecessary non-greedy quantifier
Issue: -
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.
a{3}?
). - The quantifier is effectively possessive (e.g.
a+?b
).
/* eslint regexp/no-useless-lazy: "error" */
/* ✓ GOOD */
var foo = /a*?/;
var foo = /a+?/;
var foo = /a{4,}?/;
var foo = /a[\s\S]*?bar/;
/* ✗ BAD */
var foo = /a{1}?/;
var foo = /a{4}?/;
var foo = /ab+?c/;