\xHH matches one character by its two-digit hexadecimal byte value (0x00–0xFF). It covers ASCII letters, digits, and control characters such as newline (\x0A) and tab (\x09).
Remember
\xHH → character at hex byte HH
\x41 → "A" (65 decimal)
\x0A → newline (same as \n)
\x09 → tab (same as \t)
\x20 → space
exactly 2 hex digits (pad with 0)
range: 0x00 … 0xFF
Write two hex digits after \x, then test or match as usual.
Pick the character’s byte value in hex (0–FF). Pad with a leading zero if needed.
Put \xHH in a regex literal or RegExp pattern — e.g. /\x41/.
Call test, match, or split on your string.
For common controls, prefer \n / \t when readability matters; use hex when a spec lists 0xNN codes.
Piece
Required?
Role
\x
Yes
Starts a hex byte escape
Two hex digits
Yes
0–9, A–F (case-insensitive)
Character class
Optional
e.g. [\x30-\x39] for ASCII digits
Pseudocode
Pseudocode
pattern contains "\x" + HH // HH = two hex digits
byte = parse_hex(HH) // 0 … 255
target = character(byte)
for each char in input:
if char == target:
match this position
else:
try next / fail
Reference
Cheat Sheet
Keep these hex escapes handy while writing patterns.
Topic
Detail
Syntax
\xHH (exactly two hex digits)
Letter A
\x41
Newline (LF)
\x0A or \n
Tab (HT)
\x09 or \t
Space
\x20
ASCII digits
[\x30-\x39] (= [0-9])
vs Unicode
\uXXXX for values above 0xFF
Standard
ES3+ (universal)
Try it
Live Preview
Pick a hex escape and see what character it matches against a sample string.
Browser demo of \xHH — same idea as the examples below.
Result
/\x41/.test("ABC")
→ true
/* 0x41 = 65 = "A" */
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Match the Letter A with \x41
Use a hex escape to test for the character at byte 0x41.
Hex range in a class.\x30 is "0", \x39 is "9" — same as [0-9].
Global match./[\x30-\x39]+/g finds digit runs "25" and "99".
Same ASCII character. For U+0000–U+00FF, \xHH and \u00HH match the same code.
When to switch. Need values above 0xFF? Use \uXXXX.
Edge Cases & Pitfalls
Check these before relying on \xHH in real patterns.
syntax
Exactly two hex digits
Write \x0A, not \xA. A single digit after \x is a syntax error.
range
Max value is 0xFF
\xHH cannot express code points above 255. Use \uXXXX (or a literal) instead.
readability
Prefer \n / \t when clear
Hex is great for specs and protocols. For everyday newlines and tabs, shorthands are easier to read.
unicode
Not a UTF-8 byte matcher
JavaScript strings are UTF-16 code units. Multi-byte UTF-8 sequences are not one \xHH unit.
Compatibility
Browser & Runtime Support
The \xHH hex byte escape is part of core JavaScript regular expression syntax (ES3+).
✓ Baseline · ES3+
RegExp \xHH
Supported in every browser and Node.js version. \x plus two hex digits matches that byte value.
99%Universal syntax
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
\xHHExcellent
Bottom line: Safe everywhere. Use \xHH for ASCII and Latin-1 byte values up to 0xFF; switch to \uXXXX above that.
Analysis
Performance Notes
Approach
Cost
Best for
/\x41/
O(n) scan
Matching one fixed character
/A/ literal
O(n) scan
Readable ASCII letters (same cost)
[\x30-\x39]
O(n) scan
ASCII digit runs; same as [0-9]
Hex escapes are resolved when the pattern is compiled. At match time they behave like a single literal character — no extra runtime cost versus writing A or \n directly.
Remember
Key Takeaways
Role: match one character by two-digit hex byte (0x00–0xFF).
One line:\xHH is a compact hex byte escape — pad to two digits, stay within 0xFF, prefer \n/\t when clearer.
Frequently Asked Questions
\x followed by exactly two hexadecimal digits matches the character whose byte value equals that number (0x00–0xFF). For example, \x41 matches A (65) and \x0A matches a line feed.
Exactly two. \x41 is valid for A; \x4 alone is a syntax error. Pad single-digit values with a leading zero, such as \x0A for newline.
\xHH uses two hex digits (0–255). \uXXXX uses four hex digits (U+0000–U+FFFF). For ASCII, \x41 and \u0041 match the same character.
Yes. Both match the line feed character (U+000A). \n is the readable shorthand; \x0A is the explicit hex form.
No. Values above 0xFF need \uXXXX (or a literal / Unicode escape). \xHH only covers one byte.
\xHH is core JavaScript syntax since ES3. It works in every modern browser and Node.js version.