Skip to content

Files

Latest commit

 

History

History
22 lines (15 loc) · 575 Bytes

no-misleading-capturing-group.md

File metadata and controls

22 lines (15 loc) · 575 Bytes

Pattern: Misleading capturing group

Issue: -

Description

This rule reports capturing groups that capture less text than their pattern might suggest.

E.g. in /a+(a*)/, (a*) will always capture 0 characters because all as are already consumed by a+. This is quite surprising behavior because a* suggests that the capturing group captures as many as as possible.

Examples

/* eslint regexp/no-misleading-capturing-group: "error" */
/* ✓ GOOD */
var foo = /a+(b*)/

/* ✗ BAD */
var foo = /a+(a*)/
var foo = /\w+(\d*)/
var foo = /^(a*).+/