useUnicodeRegex
このコンテンツはまだ日本語訳がありません。
Summary
Section titled “Summary”- Rule available since:
v2.4.5 - Diagnostic Category:
lint/nursery/useUnicodeRegex - This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Same as
require-unicode-regexp
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useUnicodeRegex": "error" } } }}Description
Section titled “Description”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
Examples
Section titled “Examples”Invalid
Section titled “Invalid”/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 ignoredRelated links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.