# no-empty-group

Rule `sonarjs/no-empty-group`. Regular expressions should not contain empty groups

- 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: #1263 by reach, #564 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const dateRegex = /^(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\d\d(?:)$/; // Noncompliant, useless group at the end
const methodCallRegex = /foo()/;  // Noncompliant, will match only 'foo'
```

### Correct: the rule accepts this

```js
const dateRegex = /^(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\d\d$/;
const methodCallRegex = /foo\(\)/; // OK, matches 'foo()'
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-empty-group": "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/no-empty-collection](https://lintradar.dev/rules/sonarjs/no-empty-collection.md): Empty collections should not be accessed or iterated
- [sonarjs/no-empty-parameterized-test-dataset](https://lintradar.dev/rules/sonarjs/no-empty-parameterized-test-dataset.md): Parameterized tests should not have empty datasets
- [sonarjs/no-empty-character-class](https://lintradar.dev/rules/sonarjs/no-empty-character-class.md): Empty character classes should not be used
- [sonarjs/no-empty-test-title](https://lintradar.dev/rules/sonarjs/no-empty-test-title.md): Test and suite titles should not be empty or whitespace-only
- [sonarjs/no-empty-alternatives](https://lintradar.dev/rules/sonarjs/no-empty-alternatives.md): Alternation in regular expressions should not contain empty alternatives
- [sonarjs/no-equals-in-for-termination](https://lintradar.dev/rules/sonarjs/no-equals-in-for-termination.md): Equality operators should not be used in "for" loop termination conditions

---

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