# concise-regex

Rule `sonarjs/concise-regex`. Regular expression quantifiers and character classes should be used concisely

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1194 by reach, #495 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/concise-regex` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-6353/) |

## Code examples

### Incorrect: the rule reports this

```js
/a{1,}/; // Noncompliant, '{1,}' quantifier is the same as '+'
/[A-Za-z0-9_]/; // Noncompliant, '\w' is equivalent
```

### Correct: the rule accepts this

```js
/a+/;
/\w/;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/concise-regex": "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

- [sonarjs/comma-or-logical-or-case](https://lintradar.dev/rules/sonarjs/comma-or-logical-or-case.md): Comma and logical OR operators should not be used in switch cases
- [sonarjs/constructor-for-side-effects](https://lintradar.dev/rules/sonarjs/constructor-for-side-effects.md): Objects should not be created to be dropped immediately without being used
- [sonarjs/code-eval](https://lintradar.dev/rules/sonarjs/code-eval.md): Dynamic code execution should not use user-controlled data
- [sonarjs/content-length](https://lintradar.dev/rules/sonarjs/content-length.md): HTTP request content length should be limited
- [sonarjs/class-name](https://lintradar.dev/rules/sonarjs/class-name.md): Class names should comply with a naming convention
- [sonarjs/content-security-policy](https://lintradar.dev/rules/sonarjs/content-security-policy.md): Content security policy fetch directives should not be disabled

---

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