> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-regex-spaces

[Added in v0.5.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.0)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ js.configs.recommended | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-regex-spaces': 'error',
    },
  },
]);
```

## Rule Details

Disallow multiple spaces in regular expressions. Two or more consecutive space
characters are hard to count by eye; an explicit `{n}` quantifier expresses the
same pattern unambiguously. The rule applies to both regex literals and the
`RegExp` / `new RegExp` constructors (skipped when `RegExp` is shadowed in the
enclosing scope or when the flags argument cannot be statically determined).
Consecutive spaces inside character classes (`[...]`) are intentionally allowed
and not reported.

Examples of **incorrect** code for this rule:

```javascript
var re = /foo   bar/;
var re = new RegExp('foo   bar');
```

Examples of **correct** code for this rule:

```javascript
var re = /foo {3}bar/;
var re = new RegExp('foo {3}bar');
var re = /[  ]/;
```

## Autofix

When the parsed pattern and the raw source text agree (typically any regex
literal, and `RegExp` / `new RegExp` calls whose pattern string contains no
escape sequences), the rule rewrites `  ` into ` {n}`. When the pattern
contains escape sequences that differ from the raw source (e.g.
`new RegExp('\\d  ')`), the rule reports but does not autofix — the index into
the parsed pattern would not map cleanly back to source positions.

## Differences from ESLint

- Constructor patterns using capture names or Unicode properties newer than
  the bundled TypeScript parser's Unicode data can be skipped.
- For a constructor pattern with a negated `v` class where a range is followed
  by a string-valued operand, rslint skips a report that ESLint may emit because
  JavaScript rejects the pattern.

## Original Documentation

- [ESLint: no-regex-spaces](https://eslint.org/docs/latest/rules/no-regex-spaces)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-regex-spaces.js)
