# no-regex-spaces

Rule `sonarjs/no-regex-spaces`. Regular expressions should not contain multiple spaces

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1311 by reach, #612 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const pattern = /Hello,   world!/;
```

### Correct: the rule accepts this

```js
const pattern = /Hello, {3}world!/;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-regex-spaces": "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

- [eslint/no-regex-spaces](https://lintradar.dev/rules/eslint/no-regex-spaces.md): Disallow multiple spaces in regular expressions
- [sonarjs/no-referrer-policy](https://lintradar.dev/rules/sonarjs/no-referrer-policy.md): HTTP Referrer-Policy should not be set to an unsafe value
- [sonarjs/no-same-argument-assert](https://lintradar.dev/rules/sonarjs/no-same-argument-assert.md): Assertions should not be given twice the same argument
- [sonarjs/no-redundant-optional](https://lintradar.dev/rules/sonarjs/no-redundant-optional.md): Optional properties should not redundantly include 'undefined'
- [sonarjs/no-same-line-conditional](https://lintradar.dev/rules/sonarjs/no-same-line-conditional.md): Conditionals should start on new lines
- [sonarjs/no-redundant-jump](https://lintradar.dev/rules/sonarjs/no-redundant-jump.md): Jump statements should not be redundant

---

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