fixhunt

eslint no-regex-spaces: fix changes program behavior

fix-changes-behaviorlabelled safeprogram-bug · lowrelated
Findings / 2026-10-22T18-18-44-853Z-8ihx-eslint-no-regex-spaces / r2-p005eslint 9.39.54 → 2 lines2026-10-22 18:18 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

ASI and semicolon-less code, leading ( or [ on the next line

Program

before
1let x = /hello world/.test('hello world')
2(() => { console.log('IIFE ran'); })()
after
1let x = /hello {2}world/.test('hello world')
2(() => { console.log('IIFE ran'); })()

Output

stdout beforeexit 1
(no stdout)
TypeError: /hello  world/.test(...) is not a function
stdout afterexit 1
(no stdout)
TypeError: /hello {2}world/.test(...) is not a function
fired
1 before · 0 after
runs
each version twice, same file name, no network
minimizer
12 oracle evaluations · Lightning proposal rejected

Judge Nemotron 3 Ultra advisory program-bug · low

The program fails before the fix with a TypeError because the regex literal is immediately followed by `.test` without a semicolon, causing the parser to treat the IIFE as a call argument. The fix only changes the regex pattern from two spaces to `{2}`, which does not alter the parsing error. The observed difference is due to a pre-existing syntax issue unrelated to the rule's rewrite.

Explanation Nemotron 3 Super unverified

The regex literal `/hello world/` contains two spaces between hello and world; its test method expects exactly that sequence in the string argument `'hello world'`, which matches, so `.test` returns true. Replacing the two spaces with `{2}` yields `/hello {2}world/`, where `{2}` is interpreted as a quantifier applying to the preceding space character, requiring exactly two spaces—this still matches the same input, but the resulting regex object’s source differs, causing any reliance on its string representation (e.g., debugging, serialization) to diverge. More critically, if the original regex relied on flags or other properties unchanged here, the behavioral difference arises because the fix altered the pattern’s structure without guaranteeing identical matching semantics across all possible inputs, violating the rule’s safety claim. However, in this specific case both patterns match the given string equally; the observed error stems from a tool misinterpretation, not semantic change. Nonetheless, rewriting regex literals risks altering behavior for edge cases involving whitespace quantification, making the fix unsafe in general.

Reproduce

file
prog.js (the before program)
minimized program
r2-p005.js
evidence sheet
r2-p005.md
regression fixture
r2-p005.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js
npx eslint --no-config-lookup --rule 'no-regex-spaces: error' --fix prog.js
node prog.js

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

no-regex-spaces fix · no-regex-spaces regex literal spaces · eslint no-regex-spaces quantifier replacement · regex space to curly brace fix

Details

program
ASI Semicolon-less Leading Paren Bracket Next Line
hazard
ASI and semicolon-less code, leading ( or [ on the next line
oracle
stderr before: TypeError: /hello world/.test(...) is not a function stderr after: TypeError: /hello {2}world/.test(...) is not a function
run
2026-10-22T18-18-44-853Z-8ihx-eslint-no-regex-spaces
generated program (4 lines) and the fix's diff
1let x = /hello world/.test('hello world')
2
3(() => { console.log('IIFE ran'); })()
4console.log(x);
--- orig.js	2026-10-22 14:19:13.258701439 -0400
+++ fixed.js	2026-10-22 14:19:17.125850484 -0400
@@ -1,4 +1,4 @@
-let x = /hello  world/.test('hello  world')
+let x = /hello {2}world/.test('hello  world')
 
 (() => { console.log('IIFE ran'); })()
 console.log(x);
rule documentation given to the models
Rule: no-regex-spaces
Fixable: code
Type: suggestion
Deprecated: no
Description: Disallow multiple spaces in regular expressions
Docs: https://eslint.org/docs/latest/rules/no-regex-spaces

---
title: no-regex-spaces
rule_type: suggestion
related_rules:
- no-div-regex
- no-control-regex
---





Regular expressions can be very complex and difficult to understand, which is why it's important to keep them as simple as possible in order to avoid mistakes. One of the more error-prone things you can do with a regular expression is to use more than one space, such as:

```js
const re = /foo   bar/;
```

In this regular expression, it's very hard to tell how many spaces are intended to be matched. It's better to use only one space and then specify how many spaces are expected, such as:

```js
const re = /foo {3}bar/;
```

Now it is very clear that three spaces are expected to be matched.

## Rule Details

This rule disallows multiple spaces in regular expression literals.

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

::: incorrect

```js
/*eslint no-regex-spaces: "error"*/

const re = /foo   bar/;
const re1 = new RegExp("foo   bar");
```

:::

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

::: correct

```js
/*eslint no-regex-spaces: "error"*/

const re = /foo {3}bar/;
const re1 = new RegExp("foo {3}bar");
```

:::

## Options

This rule has no options.

## When Not To Use It

If you want to allow multiple spaces in a regular expression, then you can safely turn this rule off.