跳转到内容

useUnicodeRegex

此内容尚不支持你的语言。

biome.json
{
"linter": {
"rules": {
"nursery": {
"useUnicodeRegex": "error"
}
}
}
}

Enforce the use of the u or v flag for regular expressions.

The u flag (Unicode mode) and v flag (Unicode Sets mode) enable proper handling of Unicode characters in regular expressions. Without these flags, regex patterns may not correctly match Unicode characters like emoji or characters outside the Basic Multilingual Plane.

The u flag was introduced in ES2015 and enables:

  • Correct handling of surrogate pairs (e.g., emoji)
  • Unicode code point escapes (\u{...})
  • Case-insensitive matching for Unicode characters

The v flag was introduced in ES2024 and provides all u flag features plus:

  • Set notation in character classes
  • String literals in character classes
  • Improved Unicode property escapes
/foo/;
code-block.js:1:1 lint/nursery/useUnicodeRegex  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This regular expression is missing the u or v flag.

> 1 │ /foo/;
^^^^^
2 │

Without the u or v flag, this regular expression may not correctly handle Unicode characters, such as emoji or characters outside the Basic Multilingual Plane.

The u flag enables Unicode mode which correctly handles surrogate pairs and Unicode escapes. The v flag (ES2024) enables Unicode Sets mode with additional features like set notation in character classes.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Safe fix: Add the u flag.

1 │ /foo/u;
+
/foo/gi;
code-block.js:1:1 lint/nursery/useUnicodeRegex  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This regular expression is missing the u or v flag.

> 1 │ /foo/gi;
^^^^^^^
2 │

Without the u or v flag, this regular expression may not correctly handle Unicode characters, such as emoji or characters outside the Basic Multilingual Plane.

The u flag enables Unicode mode which correctly handles surrogate pairs and Unicode escapes. The v flag (ES2024) enables Unicode Sets mode with additional features like set notation in character classes.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Safe fix: Add the u flag.

1 - /foo/gi;
1+ /foo/giu;
2 2

new RegExp("foo");
code-block.js:1:1 lint/nursery/useUnicodeRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This regular expression is missing the u or v flag.

> 1 │ new RegExp(“foo”);
^^^^^^^^^^^^^^^^^
2 │

Without the u or v flag, this regular expression may not correctly handle Unicode characters, such as emoji or characters outside the Basic Multilingual Plane.

The u flag enables Unicode mode which correctly handles surrogate pairs and Unicode escapes. The v flag (ES2024) enables Unicode Sets mode with additional features like set notation in character classes.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

new RegExp("foo", "gi");
code-block.js:1:1 lint/nursery/useUnicodeRegex  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This regular expression is missing the u or v flag.

> 1 │ new RegExp(“foo”, “gi”);
^^^^^^^^^^^^^^^^^^^^^^^
2 │

Without the u or v flag, this regular expression may not correctly handle Unicode characters, such as emoji or characters outside the Basic Multilingual Plane.

The u flag enables Unicode mode which correctly handles surrogate pairs and Unicode escapes. The v flag (ES2024) enables Unicode Sets mode with additional features like set notation in character classes.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Safe fix: Add the u flag.

1 - new·RegExp(foo,·gi);
1+ new·RegExp(foo,·giu);
2 2

/foo/u;
/foo/v;
/foo/giu;
new RegExp("foo", "u");
new RegExp("foo", "giv");
new RegExp("foo", flags); // dynamic flags are ignored