# prefer-named-capture-group

Rule `eslint/prefer-named-capture-group`. Enforce using named capture group in regular expression

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 2.2M weekly downloads of presets that enable it
- Trend: +137.0% last quarter
- Rank: #1490 by reach, #83 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `prefer-named-capture-group` | no | suggestion | package `eslint` | [docs](https://eslint.org/docs/latest/rules/prefer-named-capture-group) |
| Oxlint | `prefer-named-capture-group` | no | no | plugin `eslint`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/prefer-named-capture-group.html) |
| Biome | `style/useNamedCaptureGroup` | no | no | group style, since 2.4.5 | [docs](https://biomejs.dev/linter/rules/use-named-capture-group/) |

## Code examples

### Incorrect: the rule reports this

```js
const foo = /(ba[rz])/;
const bar = new RegExp('(ba[rz])');
const baz = RegExp('(ba[rz])');

foo.exec('bar')[1]; // Retrieve the group result.
```

### Correct: the rule accepts this

```js
const foo = /(?<id>ba[rz])/;
const bar = new RegExp('(?<id>ba[rz])');
const baz = RegExp('(?<id>ba[rz])');
const xyz = /xyz(?:zy|abc)/;

foo.exec('bar').groups.id; // Retrieve the group result.
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "prefer-named-capture-group": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "prefer-named-capture-group": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useNamedCaptureGroup": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [eslint/no-negated-condition](https://lintradar.dev/rules/eslint/no-negated-condition.md): Disallow negated conditions
- [eslint/logical-assignment-operators](https://lintradar.dev/rules/eslint/logical-assignment-operators.md): Require or disallow logical assignment operator shorthand
- [eslint/no-warning-comments](https://lintradar.dev/rules/eslint/no-warning-comments.md): Disallow specified warning terms in comments
- [eslint/no-restricted-imports](https://lintradar.dev/rules/eslint/no-restricted-imports.md): Disallow specified modules when loaded by `import`
- [eslint/func-name-matching](https://lintradar.dev/rules/eslint/func-name-matching.md): Require function names to match the name of the variable or property to which they are assigned
- [eslint/no-eq-null](https://lintradar.dev/rules/eslint/no-eq-null.md): Disallow `null` comparisons without type-checking operators

---

Web page: https://lintradar.dev/rules/eslint/prefer-named-capture-group. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
