ESLint v8.x reached end-of-life on 2024-10-05 and is no longer maintained. Upgrade or consider long-term support options
Versions

no-div-regex

Disallow equal signs explicitly at the beginning of regular expressions

🔧 Fixable

Some problems reported by this rule are automatically fixable by the --fix command line option

Characters /= at the beginning of a regular expression literal can be confused with a division assignment operator.

function bar() { return /=foo/; }

Rule Details

This rule forbids equal signs (=) after the slash (/) at the beginning of a regular expression literal, because the characters /= can be confused with a division assignment operator.

Examples of incorrect code for this rule:

Open in Playground
/*eslint no-div-regex: "error"*/

function bar() { return /=foo/; }

Examples of correct code for this rule:

Open in Playground
/*eslint no-div-regex: "error"*/

function bar() { return /[=]foo/; }

Version

This rule was introduced in ESLint v0.1.0.

Resources

Change Language