UUID v4
intermediateMatches UUID version 4 strings in standard hyphenated format.
Pattern
/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/giTry It
Explanation
Matches UUID v4: 8-4-4-4-12 hex digit groups separated by hyphens. The version nibble (position 13) must be 4, and the variant nibble (position 17) must be 8, 9, a, or b.
When to Use
Use this pattern to validate UUID v4 identifiers in API requests, database records, or configuration files. UUID v4 is the most common version, generated from cryptographically random numbers (RFC 4122). If you need to match any UUID version (v1 through v5), use the 'Any version' variation instead. For generating UUIDs, use crypto.randomUUID() in JavaScript or uuid.uuid4() in Python rather than building them with regex.
Step-by-Step Breakdown
| Token | Explanation |
|---|---|
[0-9a-f]{8} | Match 8 hexadecimal characters — the time-low field |
- | Match a literal hyphen separator |
[0-9a-f]{4} | Match 4 hex characters — the time-mid field |
- | Match a literal hyphen separator |
4[0-9a-f]{3} | Match the version nibble '4' followed by 3 hex characters — identifies this as UUID version 4 |
- | Match a literal hyphen separator |
[89ab][0-9a-f]{3} | Match the variant nibble (8, 9, a, or b) followed by 3 hex characters — indicates the RFC 4122 variant |
- | Match a literal hyphen separator |
[0-9a-f]{12} | Match 12 hex characters — the node field (typically random in v4) |
Common Mistakes
Not checking the version nibble — using [0-9a-f]{4} for the third group
Fix: 4[0-9a-f]{3}The third group's first character must be '4' for UUID v4. Without this check, the pattern matches UUIDs of any version (v1, v3, v5, etc.).
Not checking the variant nibble — using [0-9a-f]{4} for the fourth group
Fix: [89ab][0-9a-f]{3}The fourth group's first character must be 8, 9, a, or b per RFC 4122. Without this, the pattern accepts non-standard UUID variants.
Forgetting case insensitivity when matching UUIDs
Fix: Use the i flag or include A-F in character classesUUIDs are often represented in uppercase (550E8400-E29B-...) or mixed case. The i flag ensures both cases match.
Test Strings
Matching
- 550e8400-e29b-41d4-a716-446655440000
- 6ba7b810-9dad-41d1-80b4-00c04fd430c8
Non-matching
- 550e8400-e29b-31d4-a716-446655440000
- not-a-uuid
- 550e8400e29b41d4a716446655440000
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full support |
| RUBY | Full support |
| CSHARP | Full support |
Code Snippets
const regex = /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gi;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);Common Variations
Any version
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}Matches any UUID version
Related Patterns
Learn the Concepts
This pattern uses concepts covered in these lessons: