---
# Don't modify this file manually. This file is auto generated from source, and you will lose your changes next time the website is built.
# Head to the `biomejs/biome` repository, and modify the source code in there.

title: noEmptyCharacterClassInRegex
description: Learn more about noEmptyCharacterClassInRegex
---
import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs>
<TabItem label="JavaScript (and super languages)" icon="seti:javascript">
## Summary
- Rule available since: `v1.3.0`
- Diagnostic Category: [`lint/correctness/noEmptyCharacterClassInRegex`](/reference/diagnostics#diagnostic-category)
- This rule is **recommended**, meaning it is enabled by default.
- This rule doesn't have a fix.
- The default severity of this rule is [**error**](/reference/diagnostics#error).
- Sources: 
  - Same as [`no-empty-character-class`](https://eslint.org/docs/latest/rules/no-empty-character-class)

## How to configure
```json title="biome.json"
{
	"linter": {
		"rules": {
			"correctness": {
				"noEmptyCharacterClassInRegex": "error"
			}
		}
	}
}

```
## Description
Disallow empty character classes in regular expression literals.

Empty character classes don't match anything.
In contrast, negated empty classes match any character.
They are often the result of a typing mistake.

## Examples

### Invalid

```js
/^a[]/.test("a"); // false
```

<pre class="language-text"><code class="language-text">code-block.js:1:4 <a href="https://biomejs.dev/linter/rules/no-empty-character-class-in-regex">lint/correctness/noEmptyCharacterClassInRegex</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">The regular expression includes this </span><span style="color: Tomato;"><strong>empty character class</strong></span><span style="color: Tomato;">.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>/^a[]/.test(&quot;a&quot;); // false<br />   <strong>   │ </strong>   <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty character classes don't match anything.<br /></span>    <span style="color: lightgreen;">If you want to match against </span><span style="color: lightgreen;"><strong>[</strong></span><span style="color: lightgreen;">, escape it </span><span style="color: lightgreen;"><strong>&#92;[</strong></span><span style="color: lightgreen;">.<br /></span>    <span style="color: lightgreen;">Otherwise, remove the character class or fill it.</span><br />  <br /></code></pre>

```js
/^a[^]/.test("ax"); // true
```

<pre class="language-text"><code class="language-text">code-block.js:1:4 <a href="https://biomejs.dev/linter/rules/no-empty-character-class-in-regex">lint/correctness/noEmptyCharacterClassInRegex</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">The regular expression includes this </span><span style="color: Tomato;"><strong>negated empty character class</strong></span><span style="color: Tomato;">.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>/^a[^]/.test(&quot;ax&quot;); // true<br />   <strong>   │ </strong>   <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Negated empty character classes match anything.<br /></span>    <span style="color: lightgreen;">If you want to match against </span><span style="color: lightgreen;"><strong>[</strong></span><span style="color: lightgreen;">, escape it </span><span style="color: lightgreen;"><strong>&#92;[</strong></span><span style="color: lightgreen;">.<br /></span>    <span style="color: lightgreen;">Otherwise, remove the character class or fill it.</span><br />  <br /></code></pre>

### Valid

```js
/^a[xy]/.test("ay"); // true
```

```js
/^a[^xy]/.test("ab"); // true
```

```js
/^a\[]/.test("a[]"); // true
```

## Related links

- [Disable a rule](/linter/#disable-a-rule)
- [Configure the code fix](/linter#configure-the-code-fix)
- [Rule options](/linter/#rule-options)
- [Source Code](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/lint/correctness/no_empty_character_class_in_regex.rs)
- [Test Cases](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/tests/specs/correctness/noEmptyCharacterClassInRegex)

</TabItem>
</Tabs>