The u flag: Unicode mode
The u flag makes the engine work in code points rather than UTF-16 code units, unlocks \u{...} and \p{...}, and rejects escape sequences that older patterns quietly got away with.
At a glance
- Flag letter
- u
- Property
- RegExp.prototype.unicode
- Added in
- ES2015
- Unlocks
- \u{...} code point escapes and \p{...} property escapes
- Strictness
- unknown escapes such as \- outside a class become syntax errors
- Not offered here
- the v flag (unicodeSets) is not one of the seven flags this tester exposes
In detail
Without u, the dot and every quantifier operate on UTF-16 code units. An emoji outside the basic plane is two of those, so "\u{1F600}".match(/./) returns a string of length one, which is half a character and will render as a replacement box. With u the same expression returns length two, one whole code point, and /^.$/u finally agrees that an emoji is a single character.
The flag also unlocks the readable escape forms, \u{1F600} for a code point and \p{Script=Greek} for a property. Both of those compile without u as well, and that is precisely the danger: instead of an error you get a pattern that means something else. /\p{L}/ with no u flag matches the literal text p{L}, and it will happily sit in a codebase for years.
Turning u on makes the parser strict about escapes. Identity escapes that the legacy web compatibility rules tolerated stop working, so new RegExp("\\-", "u") throws rather than matching a hyphen. That is a nuisance when you flip the flag on a long inherited pattern and a genuinely useful audit when you are trying to find out which of your patterns mean what they look like.
What u does not do is normalise anything. The precomposed é and the two character e plus combining acute look identical and still fail to match each other, with or without the flag. Normalising the input string is a separate step that no regex flag performs for you.
Examples
"\u{1F600}".match(/./)[0].length; // 1, half of a surrogate pair
"\u{1F600}".match(/./u)[0].length; // 2, one code point
/^.$/.test("\u{1F600}"); // false
/^.$/u.test("\u{1F600}"); // true/\p{L}/.test("a"); // false, \p is just a literal p without u
/\p{L}/u.test("a"); // true
new RegExp("\\-", "u"); // SyntaxError: Invalid escapeThings that catch people out
- Adding u to an old pattern can throw on syntax that was legal before. Escaped hyphens outside a character class and stray escapes such as \q are the two that show up most.
- The u flag does not normalise text. A precomposed é and an e followed by a combining accent still do not match each other.
- The v flag, which adds set operations inside character classes, is not among the seven flags this tester offers, so a pattern written for it will not compile here.
Try it: Regex Tester
Type a pattern and a test string, watch every match highlight as you go, read a plain English breakdown of each token, and check the numbered and named groups it captured.
Regex Tester
LOCAL · Browser-OnlyTest and debug regular expressions with live matching and highlights
Related Regex syntax
All regex syntax →\u{...}: code point escapes that need the u flag
The braced escape addresses any code point up to 10FFFF and makes quantifiers apply to whole characters, but only when the u flag is set.
\p{...}: Unicode property escapes, and the flag they need
Property escapes match by Unicode category or script instead of by code point range. Without the u flag they compile into something else entirely.
The i flag: case insensitive matching
How the i flag folds case in literals and ranges, what it deliberately leaves alone, and the two non-ASCII characters it starts matching once u is on.
The y flag: sticky matching at lastIndex
How the sticky flag anchors a match to the current lastIndex, why it is the right tool for a hand written tokenizer, and how it behaves alongside g.
The d flag: capture group start and end offsets
What the d flag adds to a match result, how indices.groups mirrors named captures, and when the extra offsets are worth asking the engine for.
\d: the digit class, and the digits it refuses
In JavaScript \d is exactly [0-9], even with the u flag. Here is why other engines disagree and what to use when you need Unicode digits.
Tools for this
- Regex Tester Free online regex tester - test and debug regular expressions with live matching and highlights
- Regex Playground Regex playground with live match highlighting, named groups, find and replace, and shareable links