# no-invalid-regexp

Rule `eslint/no-invalid-regexp`. Disallow invalid regular expression strings in `RegExp` constructors

- Source: eslint
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 252.6M weekly downloads of presets that enable it
- Trend: +40.3% last quarter
- Rank: #56 by reach, #946 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-invalid-regexp` | yes | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-invalid-regexp) |
| Oxlint | `no-invalid-regexp` | yes | no | plugin `eslint`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-invalid-regexp.html) |

## Code examples

### Incorrect: the rule reports this

```js
RegExp('[')

RegExp('.', 'z')

new RegExp('\\')
```

### Correct: the rule accepts this

```js
RegExp('.')

new RegExp

this.RegExp('[')
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "no-invalid-regexp": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-invalid-regexp": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [ESLint recommended](https://lintradar.dev/presets/eslint-recommended.md) | ESLint | `@eslint/js` | 64 | 178.8M | +25.9% |
| [Oxlint default](https://lintradar.dev/presets/oxlint-default.md) | Oxlint | `oxlint` | 111 | 50.8M | +183.6% |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Create React App](https://lintradar.dev/presets/react-app.md) | ESLint | `eslint-config-react-app` | 109 | 4.1M | +4.3% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [JavaScript Standard Style](https://lintradar.dev/presets/standard.md) | ESLint | `eslint-config-standard` | 161 | 3.1M | +12.9% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [Nuxt](https://lintradar.dev/presets/nuxt.md) | ESLint | `@nuxt/eslint-config` | 188 | 1.5M | +72.8% |
| [React Native](https://lintradar.dev/presets/react-native.md) | ESLint | `@react-native/eslint-config` | 79 | 1.2M | +5.8% |
| [Google TypeScript Style](https://lintradar.dev/presets/gts.md) | ESLint | `gts` | 71 | 553.3K | +10.3% |
| [neostandard](https://lintradar.dev/presets/neostandard.md) | ESLint | `neostandard` | 95 | 317.6K | +50.2% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [sonarjs/no-invalid-regexp](https://lintradar.dev/rules/sonarjs/no-invalid-regexp.md): Regular expressions should be syntactically valid
- [eslint/no-delete-var](https://lintradar.dev/rules/eslint/no-delete-var.md): Disallow deleting variables
- [eslint/no-constant-binary-expression](https://lintradar.dev/rules/eslint/no-constant-binary-expression.md): Disallow expressions where the operation doesn't affect the value
- [eslint/no-empty-static-block](https://lintradar.dev/rules/eslint/no-empty-static-block.md): Disallow empty static blocks
- [eslint/no-unassigned-vars](https://lintradar.dev/rules/eslint/no-unassigned-vars.md): Disallow `let` or `var` variables that are read but never assigned
- [eslint/no-new-native-nonconstructor](https://lintradar.dev/rules/eslint/no-new-native-nonconstructor.md): Disallow `new` operators with global non-constructor functions

---

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