pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/prefer-result-array-groups |
enforce using result array `groups` |
v1.4.0 |
🔧 This rule is automatically fixable by the --fix
CLI option.
enforce using result array
groups
This rule reports and fixes regexp result arrays where named capturing groups are accessed by index instead of using groups
.
/* eslint regexp/prefer-result-array-groups: "error" */
const regex = /(?<foo>a)(b)c/g
let match
while (match = regex.exec(str)) {
/* ✓ GOOD */
var p1 = match.groups.foo
var p2 = match[2]
/* ✗ BAD */
var p1 = match[1]
}
{
"regexp/prefer-result-array-groups": ["error", {
"strictTypes": true
}]
}
strictTypes
... Iftrue
, strictly check the type of object to determine if the string instance was used inmatch()
andmatchAll()
. Default istrue
.
This option is always on when using TypeScript.
This rule was introduced in eslint-plugin-regexp v1.4.0