# prefer-regexp-exec

Rule `sonarjs/prefer-regexp-exec`. "RegExp.exec()" should be preferred over "String.match()"

- 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: #1348 by reach, #649 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/prefer-regexp-exec` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-6594/) |

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/prefer-regexp-exec": "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

- [unicorn/prefer-regexp-exec](https://lintradar.dev/rules/unicorn/prefer-regexp-exec.md): Prefer `RegExp#exec()` over `String#match()` for non-global regular expressions.
- [typescript/prefer-regexp-exec](https://lintradar.dev/rules/typescript/prefer-regexp-exec.md): Enforce `RegExp#exec` over `String#match` if no global flag is provided
- [sonarjs/prefer-read-only-props](https://lintradar.dev/rules/sonarjs/prefer-read-only-props.md): React props should be read-only
- [sonarjs/prefer-single-boolean-return](https://lintradar.dev/rules/sonarjs/prefer-single-boolean-return.md): Return of boolean expressions should not be wrapped into an "if-then-else" statement
- [sonarjs/prefer-promise-shorthand](https://lintradar.dev/rules/sonarjs/prefer-promise-shorthand.md): Shorthand promises should be used
- [sonarjs/prefer-specific-assertions](https://lintradar.dev/rules/sonarjs/prefer-specific-assertions.md): The most specific assertion should be used

---

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