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.
Examples
Section titled “Examples”Regex Literal Without Unicode Flag
Section titled “Regex Literal Without Unicode Flag”const pattern = /abc/;const pattern = /abc/u;Regex Literal With Other Flags
Section titled “Regex Literal With Other Flags”const pattern = /abc/gi;const pattern = /abc/giu;RegExp Constructor
Section titled “RegExp Constructor”const pattern = new RegExp("abc");const pattern = new RegExp("abc", "u");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.