Skip to content

regexUnicodeFlag

Require regex patterns to have the unicode ('u') or unicodeSets ('v') flag for proper Unicode character handling.

✅ This rule is included in the ts preset.

Require regex patterns may opt into the unicode (u) or unicodeSets (v) flags for proper Unicode character handling. Without these flags, regex patterns may fail to match Unicode characters correctly, especially with surrogate pairs like emoji.

const pattern = /abc/;
const pattern = /abc/gi;
const pattern = new RegExp("abc");

This rule is not configurable.

If you don’t handle unicode characters with regular expressions, or believe you always do so correctly, this rule may cause more noise than is useful.

If you are targeting older JavaScript environments that do not support the u flag (ES6+), you may want to disable this rule. Note that patterns using escape sequences like \a that are invalid in unicode mode will not receive an auto-fix.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.