Skip to main content
Data & Formatting · In-Browser Regular Expression Lab

UUID v4 Regex — Validate 128-bit RFC 4122 Canonical UUIDs

Strictly matches version 4 UUIDs with 36 canonical characters including hyphens and version bit 4.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:c9bf9e57-1685-4c89-bafb-ff5af830be8a

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

c9bf9e57-1685-4c89-bafb-ff5af830be8a Pass
550e8400-e29b-41d4-a716-446655440000 Pass

Expected Invalid Samples (Must Reject)

c9bf9e57-1685-3c89-bafb-ff5af830be8a Rejected (Pass)
not-a-uuid Rejected (Pass)
550e8400-e29b-41d4-a716-44665544000 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
const text = "c9bf9e57-1685-4c89-bafb-ff5af830be8a";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Ensures the 3rd section starts with 4 (version) and the 4th section starts with 8, 9, a, or b (variant 1). Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
[0-9a-fA-F]{8}Time-low8 hexadecimal characters.
[0-9a-fA-F]{4}Time-mid4 hexadecimal characters.
4[0-9a-fA-F]{3}Version 4Must start with literal digit 4 followed by 3 hex chars.
[89abAB][0-9a-fA-F]{3}VariantVariant bits 8, 9, a, or b.
[0-9a-fA-F]{12}NodeFinal 12 hexadecimal characters.

Frequently Asked Questions

How to match any UUID version (v1-v5)?
Replace `4[0-9a-fA-F]{3}` with `[1-5][0-9a-fA-F]{3}`.
Browse All 40 Patterns