Validation
Match a UUID (v4)
Flags: gi
Validate or extract UUIDs (any version, or specifically v4).
Pattern
Regular expression
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}How it works
This checks canonical UUID hyphenation and constrains the version (`[1-5]`) and variant (`[89ab]`) nibbles as per RFC 4122. To accept any version, replace `[1-5]` with `[0-9a-f]`.
Matches
- ▸550e8400-e29b-41d4-a716-446655440000
- ▸9F1A0B7E-3F0C-4B0D-9A7B-6E2F0C1D2E3F
Non-matches
- ▸550e8400e29b41d4a716446655440000 (no hyphens)
- ▸not-a-uuid
- ▸550e8400-e29b-71d4-a716-446655440000 (invalid version 7 nibble)
Common gotchas
UUID v7 (time-ordered) uses version nibble 7. If you need to accept v7, expand the version class to `[1-7]`. Also, UUIDs are case-insensitive — always use the `i` flag.
Language snippets
JavaScript
const re = /[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gi;Python
re.findall(r"[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", text, re.I)Go
re := regexp.MustCompile(`(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)Java
Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", Pattern.CASE_INSENSITIVE)Related patterns
Match a CSS hex color
#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3})\b
Match a MAC address
(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}
Match an email address
[\w.+-]+@[\w-]+\.[\w.-]+
Match a URL
https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*
Match an IPv4 address
(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)
Match an IPv6 address
(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}|::1|::