Regex for UUID (v4)
Matches UUID version 4 format. The third group starts with 4, and the fourth group starts with 8, 9, a, or b.
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}$/Pattern Breakdown
| Token | Explanation |
|---|---|
| [0-9a-fA-F]{8} | First 8 hex characters |
| - | Dash separator |
| [0-9a-fA-F]{4} | Second group of 4 hex characters |
| 4[0-9a-fA-F]{3} | Version 4 indicator followed by 3 hex chars |
| [89abAB][0-9a-fA-F]{3} | Variant indicator (8/9/a/b) followed by 3 hex chars |
| [0-9a-fA-F]{12} | Final 12 hex characters |
Test Examples
| Input | Match? |
|---|---|
| 550e8400-e29b-41d4-a716-446655440000 | Match |
| 6ba7b810-9dad-41d3-80b4-00c04fd430c8 | No match |
| not-a-uuid | No match |
Common Use Cases
- UUID validation
- Database ID format checking
- API request validation
Variations
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$Any UUID version
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester