★ Dev formats · regex
Regex for UUID
Matches hyphenated UUIDs of versions 1 to 8 (including v4 random and v7 time-ordered) with the RFC variant. The nil and max UUIDs (all zeros or all f's) are special values and don't pass.
- Runs in your browser
- No signup
Try the uuid pattern
Read it in plain English (best-effort)
- ^start of a line
- [0-9a-fA-F]one character from: 0–9, a–f, A–F
- {8}exactly 8 of the previous
- -the character '-'
- [0-9a-fA-F]one character from: 0–9, a–f, A–F
- {4}exactly 4 of the previous
- -the character '-'
- [1-8]one character from: 1–8
- [0-9a-fA-F]one character from: 0–9, a–f, A–F
- {3}exactly 3 of the previous
- -the character '-'
- [89abAB]one character from: '8', '9', 'a', 'b', 'A', 'B'
- [0-9a-fA-F]one character from: 0–9, a–f, A–F
- {3}exactly 3 of the previous
- -the character '-'
- [0-9a-fA-F]one character from: 0–9, a–f, A–F
- {12}exactly 12 of the previous
- $end of a line
One sample per line works well with the m flag on anchored patterns.
The pattern, piece by piece
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/| Part | What it does |
|---|---|
[0-9a-fA-F]{8} | 8 hex digits |
-[0-9a-fA-F]{4} | 4 hex digits |
-[1-8][0-9a-fA-F]{3} | the version digit (1–8) then 3 hex digits |
-[89abAB][0-9a-fA-F]{3} | the variant: first digit 8, 9, a or b |
-[0-9a-fA-F]{12} | 12 hex digits |
What it accepts and rejects
Every sample below is checked automatically in JavaScript and Python. The tester above is preloaded with all of them, one per line.
| Should match | |
|---|---|
123e4567-e89b-12d3-a456-426614174000 | ✓ |
550e8400-e29b-41d4-a716-446655440000 | ✓ |
f47ac10b-58cc-4372-a567-0e02b2c3d479 | ✓ |
018f3b1e-7c3a-7d4e-9f00-1a2b3c4d5e6f | ✓ |
6BA7B810-9DAD-11D1-80B4-00C04FD430C8 | ✓ |
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 | ✓ |
| Should not match | |
|---|---|
123e4567e89b12d3a456426614174000 | ✗ |
123e4567-e89b-02d3-a456-426614174000 | ✗ |
123e4567-e89b-12d3-c456-426614174000 | ✗ |
00000000-0000-0000-0000-000000000000 | ✗ |
g23e4567-e89b-12d3-a456-426614174000 | ✗ |
{123e4567-e89b-12d3-a456-426614174000} | ✗ |
Copy it into your code
RE2-safeNo lookarounds or backreferences, so the same pattern works in Go's RE2 engine and in Rust's regex crate.
const uuidRe = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
export function isValidUuid(value) {
return uuidRe.test(value.trim());
}When not to use regex for this
If you only need 'is this a UUID my code can parse', use your UUID library's parser. In Postgres, a uuid column rejects bad values for free.
Questions engineers actually ask
Does it match UUID v7?
Why doesn't the nil UUID match?
What is catastrophic backtracking?
Sources
Formats were checked on 8 November 2026. Rules change; the official issuer wins if it disagrees.
More dev formats patterns
- ISO 8601 DateYYYY-MM-DD dates with valid month and day ranges. Format only.^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$
- 24-hour TimeHH:MM or HH:MM:SS in 24-hour format, 00:00 to 23:59:59.^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$
- Semantic VersionThe official semver.org pattern, with pre-release and build metadata.^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
- JWTThree base64url segments starting with eyJ. Shape only, never trust it.^eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$
- Base64Standard padded base64: groups of four with = or == padding.^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$
- MAC AddressColon, hyphen or Cisco dot notation, without mixing separators.^(?:(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}|(?:[0-9A-Fa-f]{2}-){5}[0-9A-Fa-f]{2}|(?:[0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})$
Or browse the full regex library.
More from the workbench
Fine print
Tools: on the house.
Engineer: by the hour.
The regex was free. Code that doesn't need one is the upgrade: typed schemas, validated once at the edge, trusted everywhere after.
I'm Himanshu, an AI and full-stack engineer. I build MVPs, AI agents and the growth plumbing around them for early-stage startups.
