# unused-named-groups

Rule `sonarjs/unused-named-groups`. Names of regular expressions named groups should be used

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1378 by reach, #679 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/unused-named-groups` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-5860/) |

## Code examples

### Incorrect: the rule reports this

```js
const date = "01/02";

const datePattern = /(?<month>\d{2})\/(?<year>\d{2})/;
const dateMatched = date.match(datePattern);

if (dateMatched !== null) {
  checkValidity(dateMatched[1], dateMatched[2]); // Noncompliant - numbers instead of names of groups are used
  checkValidity(dateMatched.groups.day); // Noncompliant - there is no group called "day"
}

// ...

const score = "14:1";

const scorePattern = /(?<player1>\d+):(?<player2>\d+)/; // Noncompliant - named groups are never used
const scoreMatched = score.match(scorePattern);

if (scoreMatched !== null) {
  checkScore(score);
}
```

### Correct: the rule accepts this

```js
const date = "01/02";

const datePattern = /(?<month>\d{2})\/(?<year>\d{2})/;
const dateMatched = date.match(datePattern);

if (dateMatched !== null) {
  checkValidity(dateMatched.groups.month, dateMatched.groups.year);
}

// ...

const score = "14:1";

const scorePattern = /(?<player1>\d+):(?<player2>\d+)/;
const scoreMatched = score.match(scorePattern);

if (scoreMatched !== null) {
  checkScore(scoreMatched.groups.player1);
  checkScore(scoreMatched.groups.player2);
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/unused-named-groups": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/unused-import](https://lintradar.dev/rules/sonarjs/unused-import.md): Unnecessary imports should be removed
- [sonarjs/unverified-certificate](https://lintradar.dev/rules/sonarjs/unverified-certificate.md): Server certificates should be verified during SSL/TLS connections
- [sonarjs/todo-tag](https://lintradar.dev/rules/sonarjs/todo-tag.md): Track uses of "TODO" tags
- [sonarjs/unverified-hostname](https://lintradar.dev/rules/sonarjs/unverified-hostname.md): Server hostnames should be verified during SSL/TLS connections
- [sonarjs/testing-library-query-assertion](https://lintradar.dev/rules/sonarjs/testing-library-query-assertion.md): Testing Library queries should match presence assertions
- [sonarjs/updated-const-var](https://lintradar.dev/rules/sonarjs/updated-const-var.md): "const" variables should not be reassigned

---

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