UUID (v4)Regex — Pattern, Examples & Code
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iWhat it matches / doesn't match
| Matches ✅ | Does not match ❌ |
|---|---|
●550e8400-e29b-41d4-a716-446655440000 | ●550e8400e29b41d4a716446655440000 |
●f47ac10b-58cc-4372-a567-0e02b2c3d479 | ●not-a-uuid-at-all |
●550e8400-e29b-31d4-a716-446655440000 |
How it works
Matches UUID v4 strings in the standard 8-4-4-4-12 hyphenated format. The third group is locked to start with '4' (the version identifier) and the fourth group starts with 8, 9, a, or b (the RFC 4122 variant bits). Case-insensitive flag handles both uppercase and lowercase hex digits.
Code Usage
JavaScript
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
regex.test("550e8400-e29b-41d4-a716-446655440000"); // truePython
import re
pattern = re.compile(r'^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', re.IGNORECASE)
bool(pattern.match("550e8400-e29b-41d4-a716-446655440000")) # TrueGo
import "regexp"
r := regexp.MustCompile(`(?i)^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
r.MatchString("550e8400-e29b-41d4-a716-446655440000") // trueNeed a custom regex for a different use case?
Generate a custom regex with AI →FAQ
What does the UUID (v4) regex pattern match?
Matches UUID v4 strings in the standard 8-4-4-4-12 hyphenated format. The third group is locked to start with '4' (the version identifier) and the fourth group starts with 8, 9, a, or b (the RFC 4122 variant bits). Case-insensitive flag handles both uppercase and lowercase hex digits.
How do I use the UUID (v4) regex in JavaScript?
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; regex.test("550e8400-e29b-41d4-a716-446655440000"); // true
Can I use the UUID (v4) regex in Python?
Yes. import re pattern = re.compile(r'^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', re.IGNORECASE) bool(pattern.match("550e8400-e29b-41d4-a716-446655440000")) # True
