Regex for Matching a UUID
Matches the standard 8-4-4-4-12 hexadecimal UUID format.
Published October 11, 2026
This regex matches the standard 8-4-4-4-12 hexadecimal UUID format (any version).
How the pattern works
Breaking the pattern down: [0-9a-fA-F]{8} = 8 hex digits; - = dashes between groups.
Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.
Pattern tests
/^[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}$/
✓ '123e4567-e89b-12d3-a456-426614174000'
✗ '123e4567e89b12d3a456426614174000'
✗ 'not-a-uuid'
Practical examples
The pattern
const re = /^[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}$/Test it
const re = /^[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}$/
re.test('123e4567-e89b-12d3-a456-426614174000') // true
re.test('123e4567e89b12d3a456426614174000') // false
re.test('not-a-uuid') // falseIn Python
import re
re.search(r'^[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}$', text)Common mistakes
- Allowing braces or URNs unintentionally.
- Not enforcing version bits when needed.
- Case sensitivity.
Key takeaways
- Anchors (^ and $) make the whole string match instead of a part of it.
- Regex checks format only; verify data separately when it matters.
- Test with valid and invalid samples.
FAQ
Validate version 4 only?
Use [4] as the first digit of group 3 and [89ab] for group 4.
Where can I test this pattern?
Use the Regex Tester on this site, or regex101.com.