JavaScript RegExp \uXXXX Metacharacter

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Unicode escape

What You’ll Learn

The \uXXXX escape matches a Unicode character by its four-digit hexadecimal code point. Use it when you need to target a specific symbol—such as ©, é, or ♥—without typing the character directly in your source code.

01

Syntax

\u + 4 hex

02

Example

\u0041 = A

03

Range

U+0000–U+FFFF

04

vs \xHH

2 vs 4 digits

05

Classes

[\u2665\u2605]

06

Emoji

\u{...} + u flag

Introduction

Every character in a JavaScript string has a numeric Unicode code point. The \uXXXX escape lets you refer to that character using exactly four hexadecimal digits after \u—both in string literals and inside regular expressions.

This is especially useful when the character is hard to type, invisible on your keyboard, or when you want your source code to stay ASCII-only while still matching international text, symbols, or control characters by their exact code point.

Understanding the \uXXXX Metacharacter

\uXXXX matches one UTF-16 code unit whose value equals the four hex digits. For example, \u0041 is the letter A (U+0041), and \u00A9 is the copyright sign © (U+00A9).

JavaScript
/\u0041/.test("A");        // true
/\u0041/.test("B");        // false
/\u00A9/.test("© 2026");   // true

"A" === "\u0041";          // true (same in strings)

The escape works identically in regex patterns and JavaScript strings. In a pattern, /\u00E9/ matches the character é just as the literal /é/ would.

💡
Beginner Tip

Think of XXXX as a placeholder: replace each X with a hex digit (0–9 or A–F). \u0041 means “match the character at Unicode position 0041.”

How to Use \uXXXX in JavaScript

Use \uXXXX in detection, replacement, validation, and character-class patterns:

JavaScript
/\u00E9/.test("café");              // true
"hello\u2665".match(/\u2665/);     // ["♥"]
"© 2026".replace(/\u00A9/g, "(c)"); // "(c) 2026"
/[\u2665\u2605\u2728]/.test("★");   // true

Combine multiple Unicode escapes inside a character class [...] to match any of several symbols. Use the global flag when replacing every occurrence.

📝 Syntax

JavaScript
\uXXXX          // one Unicode code unit (4 hex digits)
\u0041          // letter A (U+0041)
\u00A9          // copyright © (U+00A9)
[\u2665\u2605]  // heart OR star in a class
/\u{1F600}/u    // emoji 😀 (braced form, needs u flag)

Common patterns

  • /\u0041/ — match the letter A by code point.
  • /\u00A9/ — detect a copyright symbol.
  • /[\u00E0-\u00FF]/ — match Latin accented letters in a range.
  • /\u{1F600}/u — match emoji with the braced form and u flag.

⚡ Quick Reference

GoalPattern
Match letter A\u0041
Match copyright ©\u00A9
Match é (e-acute)\u00E9
Match heart ♥\u2665
Two-digit byte escape\xHH
Emoji (any code point)\u{...} with u flag

📋 \uXXXX vs \xHH vs \u{...}

Three escape forms for matching characters by numeric value.

Unicode (4 hex)
\uXXXX

U+0000 to U+FFFF

Hex byte (2 hex)
\xHH

0x00 to 0xFF only

Braced Unicode
\u{1F600}

Any code point + u flag

Literal char
/é/

Same as \u00E9

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples cover basic matching, symbols, accented letters, heart characters, and Unicode character classes.

📚 Getting Started

Match a letter by its Unicode code point.

Example 1 — Match the Letter A with \u0041

Return true when the string contains the character at U+0041.

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

How It Works

\u0041 is the Unicode code point for capital A. The regex engine converts the escape to that character before matching, so /\u0041/ behaves exactly like /A/.

📈 Practical Patterns

Match symbols, accented text, and Unicode character sets.

Example 3 — Match an Accented Letter (é)

Find the e-acute character in French text using U+00E9.

JavaScript
const word = "café";

console.log(/\u00E9/.test(word));       // true
console.log(word.replace(/\u00E9/g, "e")); // "cafe"
Try It Yourself

How It Works

Accented characters above ASCII often have code points in the U+0080–U+00FF range. \u00E9 targets é precisely without relying on keyboard layout.

Example 4 — Match a Heart Symbol (♥)

Locate the black heart suit character at U+2665.

JavaScript
const msg = "I ♥ JavaScript";

const found = msg.match(/\u2665/);
console.log(found[0]); // "♥"
console.log(found.index); // 2
Try It Yourself

How It Works

Symbols like ♥ (U+2665) sit in the Unicode symbols block. A single \uXXXX escape covers any BMP character up to U+FFFF.

Example 5 — Match Multiple Unicode Symbols in a Class

Extract hearts, stars, and sparkles from a rating string.

JavaScript
const pattern = /[\u2665\u2605\u2728]/g;
const text = "Rate ★★★★★ ♥ sparkle ✨";

const symbols = text.match(pattern);
console.log(symbols.join(" ")); // "★ ★ ★ ★ ★ ♥ ✨"
console.log(symbols.length);    // 7
Try It Yourself

How It Works

Character classes can list several \uXXXX escapes. The global flag collects every matching symbol in order.

🚀 Common Use Cases

  • International text — match accented letters and non-ASCII characters by code point.
  • Symbol validation — detect ©, ™, €, and other special symbols in user input.
  • ASCII-safe source — write patterns without embedding non-ASCII characters directly.
  • Log parsing — match invisible or rare Unicode characters in exported data.
  • Normalization — replace specific Unicode characters with ASCII equivalents.
  • Character filtering — allow or block specific symbols using character classes.

Important Considerations

  • Exactly four digits\u41 is invalid; always pad with leading zeros (\u0041).
  • BMP limit — single \uXXXX covers U+0000–U+FFFF; emoji above that need \u{...} with the u flag.
  • Not the same as \x\x41 is byte 0x41 (65 = A), but \x cannot reach code points above 255.
  • Case insensitive — hex digits A–F can be upper or lower case; \u0041 and \u0041 are equivalent.
  • Surrogate pairs — characters above U+FFFF are stored as two UTF-16 code units; match them with two escapes or use \u{...}.

🧠 How \uXXXX Matches Characters

1

Parse escape

The engine reads \u followed by four hex digits and converts them to a code unit value.

Decode
2

Resolve character

0041 becomes U+0041 (A); 00A9 becomes U+00A9 (©).

Map
3

Compare at position

The resolved character is compared to the next input character at the current match position.

Match
4

Advance or fail

Code unit matches → consume and continue. Mismatch → backtrack or report no match.

📝 Notes

  • \uXXXX requires exactly four hexadecimal digits (0–9, A–F).
  • The same escape works in string literals: "\u0041" produces "A".
  • For emoji and code points above U+FFFF, use /\u{1F600}/u (braced form with u flag).
  • Previous metacharacter: \t horizontal tab.
  • Next metacharacter: \v vertical tab.
  • Look up code points at the Unicode Character Database or browser DevTools string inspector.

Browser & Runtime Support

The \uXXXX Unicode escape is part of core JavaScript regular expression syntax.

Baseline · ES3+

RegExp \uXXXX

Supported in every browser and Node.js version. \u followed by four hex digits matches that Unicode code unit.

99% Universal syntax
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 everywhere. Use \uXXXX when you need a specific Unicode character without typing it literally.

Conclusion

The \uXXXX metacharacter matches a Unicode character by its four-digit hexadecimal code point. It is the standard way to reference letters, symbols, and accented characters in ASCII-safe regex patterns.

Use \u0041 for A, \u00A9 for ©, and character classes like [\u2665\u2605] for symbol sets. For emoji above U+FFFF, reach for the braced \u{...} form with the u flag. Next, learn the \v vertical tab metacharacter.

💡 Best Practices

✅ Do

  • Pad with leading zeros: \u0041 not \u41
  • Use \uXXXX when the character is hard to type
  • Group related symbols in character classes
  • Use \u{...} + u flag for emoji
  • Comment the character name next to the escape for readability

❌ Don’t

  • Omit leading zeros in the four-digit form
  • Confuse \xHH (2 digits) with \uXXXX (4 digits)
  • Expect a single \uXXXX to match emoji above U+FFFF
  • Forget the u flag when using braced \u{...}
  • Mix up code point values (verify in a Unicode table)

Key Takeaways

Knowledge Unlocked

Five things to remember about RegExp \uXXXX

Match any BMP Unicode character by its four-digit hex code point.

5
Core concepts
📈 02

U+0041

Letter A.

Example
🚫 03

\xHH

2 digits only.

Compare
🔒 04

[\u2665]

Char class.

Symbols
🔢 05

\u{...}

Emoji + u flag.

Extended

❓ Frequently Asked Questions

\u followed by exactly four hexadecimal digits matches the Unicode code unit at that value. For example, \u0041 matches the letter A (U+0041) and \u00A9 matches the copyright symbol © (U+00A9).
Exactly four. \u0041 is valid; \u41 (too few) and \u00441 (too many) are syntax errors in both string literals and regex patterns.
\xHH uses two hex digits and matches a byte value (0–255). \uXXXX uses four hex digits and matches any BMP code unit from U+0000 to U+FFFF, covering most letters, symbols, and accented characters.
Not directly with a single four-digit escape for code points above U+FFFF. Emoji require either a surrogate pair (two \u escapes) or the braced form \u{1F600} with the u flag on the regex.
The four-digit \uXXXX form works the same with or without the u flag. The u flag additionally enables the braced \u{...} syntax 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 without extra flags.
Did you know?

The escape \u0041 in a regex is the same value as typing A directly—but using the code point makes your pattern portable across editors and keyboard layouts that may not have easy access to international characters.

Continue to \v vertical tab metacharacter

Learn how the vertical tab control character differs from horizontal tab and other whitespace.

\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