JavaScript RegExp Unicode Escape Metacharacter (\uXXXX)

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

What Is \uXXXX?

\uXXXX matches one character by its Unicode code unit: the letter u plus exactly four hex digits (0–9, A–F). Example: \u0041 is the letter A.

Remember
\u0041 → "A"     (U+0041)
\u00A9 → "©"     (U+00A9)
\u2665 → "♥"     (U+2665)

/\u0041/.test("A")     → true
/\u0041/.test("B")     → false
/\u00A9/.test("© 2026") → true
UsePrefer
Match a letter by code/\u0041/ for A
Match a symbol/\u00A9/ for ©
Byte-range (0–255)\xHH
Code points above FFFF\u{…} with the u flag

How to Use \uXXXX

Look up the code point, write four hex digits, then test or replace.

  1. Find the character’s code (for example U+00A9 for ©).
  2. Write \u plus four hex digits: \u00A9.
  3. Use it in a pattern: /\u00A9/, or in a string: "\u00A9".
  4. Add flags like i or g when case or global replace matters.
PieceRequired?Role
\u + 4 hex digitsYesIdentify the code unit to match
Hex digitsYes0–9 and A–F (case-insensitive)
Range—U+0000 … U+FFFF (BMP)
FlagsOptionali, g, and others as needed

Pseudocode

Pseudocode
pattern has "\u" + fourHexDigits
target = codeUnitFromHex(fourHexDigits)   // 0 … 65535

read next character ch from the string
if ch.codeUnit === target:
    accept match
else:
    fail this path

examples:
  \u0041 → match "A"
  \u00A9 → match "©"
  \u2665 → match "♥"

Cheat Sheet

Handy codes and rules for everyday Unicode escapes.

TopicDetail
Form\u + exactly 4 hex digits
Letter A\u0041
Copyright ©\u00A9
Heart ♥\u2665
vs \xHH4 digits (BMP) vs 2 digits (0–255)
Emoji / astral\u{1F600} with /u
StandardES3+ (universal)

Live Preview

Run common \uXXXX checks against letters and symbols.

Browser demo of the RegExp \uXXXX Unicode escape — same ideas as the examples below.

Result
text = "A"
/\u0041/.test(text)
→ true

/* U+0041 is the letter A */

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Match a Letter by Code

Use \u0041 to match the letter A without typing it literally.

JavaScript
console.log(/\u0041/.test("A"));     // true
console.log(/\u0041/.test("B"));     // false
console.log(/\u0041/.test("Apple")); // true
Try It Yourself

How It Works

  1. Four digits. 0041 is the hex code for A.
  2. Exact match. "A" matches; "B" is a different code → false.
  3. Anywhere in the string. "Apple" starts with A → true.
  4. Same as the letter. /\u0041/ and /A/ match the same character.

Example 2 — Match Symbols

Find copyright and heart symbols by their Unicode values.

JavaScript
console.log(/\u00A9/.test("© 2026")); // true
console.log(/\u2665/.test("I ♥ JS")); // true
console.log(/\u00A9/.test("(c)"));    // false
Try It Yourself

How It Works

  1. © is U+00A9. \u00A9 matches the real copyright character.
  2. ♥ is U+2665. The heart in "I ♥ JS" matches.
  3. Lookalikes fail. The text "(c)" is not the © symbol.
  4. Useful when typing is hard. Escapes keep symbols clear in source code.

Example 3 — Compare \u and \x

For values 0–255, \u00A9 and \xA9 match the same character.

JavaScript
const text = "©";

console.log(/\u00A9/.test(text)); // true
console.log(/\xA9/.test(text));   // true
console.log("\u00A9" === "\xA9"); // true
Try It Yourself

How It Works

  1. Same character. Both escapes resolve to code 169 (©).
  2. Different width. \x needs 2 hex digits; \u needs 4.
  3. Prefer \u for clarity when discussing Unicode code points.
  4. Use \x for bytes when you only care about 0–255 values.

Edge Cases & Pitfalls

Check these before relying on \uXXXX in real projects.

digits

Exactly four hex digits

\u41 and \u00441 are invalid. Always pad: \u0041.

emoji

Astral characters need braces

Code points above U+FFFF (many emoji) need \u{1F600} with the u flag—not a single four-digit \uXXXX.

escape

new RegExp needs double escaping

Write new RegExp("\\u0041"). In a string pattern argument you need two backslashes.

case

Hex letters are case-insensitive

\u00a9 and \u00A9 are the same. The i flag affects letter matching of the character, not the hex digits themselves.

Browser & Runtime Support

The \uXXXX Unicode escape is core JavaScript syntax (ES3+) and works everywhere JS runs. Braced \u{…} needs the u flag (ES2015+).

✓ Baseline · ES3+

RegExp \uXXXX

Four-digit Unicode escapes work in every modern and legacy browser, plus all Node.js versions.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
\uXXXX Excellent

Bottom line: Safe for everyday use. Prefer braced \u{…} with /u when targeting emoji or code points above U+FFFF.

Performance Notes

ApproachCostBest for
/\u0041/.test(str)O(n)Single-character detection
str.replace(/\u00A9/g, "(c)")O(n)Normalizing symbols
/[\u0041-\u005A]/O(n)Ranges of code units

Escapes compile to ordinary character matches—no special runtime cost. Prefer \xHH only when you intentionally stay in the 0–255 byte range.

Key Takeaways

  • Form: \u + exactly four hex digits → one BMP character.
  • Readable codes: \u0041 is A, \u00A9 is ©.
  • vs \x: four digits (BMP) vs two digits (0–255).
  • Emoji: use \u{…} with the u flag for code points above FFFF.

One line: \uXXXX matches a character by four hex digits — pad to four, stay in the BMP, and use \u{…}/u for emoji.

Frequently Asked Questions

\u followed by exactly four hexadecimal digits matches the Unicode code unit at that value. For example, \u0041 matches A (U+0041) and \u00A9 matches © (U+00A9).
Exactly four. \u0041 is valid; shorter or longer digit runs are syntax errors in both string literals and regex patterns.
\xHH uses two hex digits (0–255). \uXXXX uses four hex digits and covers the Basic Multilingual Plane from U+0000 to U+FFFF—most letters, symbols, and accented characters.
Not with a single four-digit escape for code points above U+FFFF. Use the braced form \u{1F600} with the u flag, or a surrogate pair of two \u escapes.
The four-digit \uXXXX form works with or without the u flag. The u flag additionally enables braced \u{...} for any Unicode code point, including emoji.
The \uXXXX escape is core JavaScript syntax since ES3. It works in every modern browser and Node.js version.

Next: \v vertical tab

Learn how the vertical tab metacharacter matches another control character.

\v tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful