regex pattern · ready to copy
Regex for matching UUIDs (v1-v5)
Match canonical UUID with hyphens. Version-agnostic.
intermediate
javascript / pcre / python4 use cases
The pattern
[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}
Test cases
| Input | Result |
|---|---|
| 550e8400-e29b-41d4-a716-446655440000 | ✓matches |
| f47ac10b-58cc-4372-a567-0e02b2c3d479 | ✓matches |
| 550e8400e29b41d4a716446655440000 (no hyphens) | ✗rejects |
| not-a-uuid | ✗rejects |
Edge cases & caveats
Strict version: replace `[1-5]` with the version digit you want. UUID v7 (time-ordered, 2024+) starts with `7` not `[1-5]` — extend to `[1-5,7]` if you need v7 too.
Common use cases
- log correlation ID extraction
- trace ID matching
- API key vs UUID disambiguation
- DB primary key lookup
Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab
Related
url · mac address · semver version · twitter handle · ↗ generate realistic test names