# Regex for UUID Validation

> UUID regex for the standard 8-4-4-4-12 format, plus a strict version-4 variation. Token-by-token breakdown and match examples included.

```
/^[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}$/
```

A UUID is 32 hexadecimal digits in an 8-4-4-4-12 grouping: five hyphen-separated blocks. This pattern validates that shape for any UUID version; the variation below pins the version nibble to 4 and the variant bits, which is what you want when your system only ever generates v4.

## Token by token

| Token | Meaning |
|---|---|
| `^[0-9a-fA-F]{8}` | first block: exactly 8 hex digits |
| `-[0-9a-fA-F]{4}` | second block: 4 hex digits (repeated for blocks three and four) |
| `-[0-9a-fA-F]{12}$` | final block: 12 hex digits, then end of string |

## Examples

- ✓ matches: `f47ac10b-58cc-4372-a567-0e02b2c3d479`
- ✓ matches: `F47AC10B-58CC-4372-A567-0E02B2C3D479`
- ✓ matches: `00000000-0000-0000-0000-000000000000`
- ✗ does not match: `f47ac10b58cc4372a5670e02b2c3d479`
- ✗ does not match: `f47ac10b-58cc-4372-a567`
- ✗ does not match: `g47ac10b-58cc-4372-a567-0e02b2c3d479`

## Variations

- `^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$` — strict v4: version nibble is 4, variant nibble is 8, 9, a, or b — add the i flag for uppercase
- `^[0-9A-HJKMNP-TV-Z]{26}$` — ULID instead: 26 chars of Crockford Base32 (no I, L, O, U)

## Language notes

- Add the i flag (or re.IGNORECASE) and you can shorten the classes to [0-9a-f].
- Most languages ship a real parser — uuid.UUID(s) in Python, uuid.Parse(s) in Go — which also normalizes case and validates versions.

## FAQ

### Should UUIDs be matched case-insensitively?

Yes — RFC 4122 outputs lowercase but requires parsers to accept uppercase. This pattern includes both ranges; with the i flag you can write it more compactly.

### How do I match only version 4 UUIDs?

Pin the two structural nibbles: the third block must start with 4 (the version) and the fourth with 8, 9, a, or b (the variant). The strict variation above does exactly that.

## Related patterns

- [Regex for Hex Color Codes](https://www.devkult.com/regex/hex-color.md)
- [Regex for IPv4 Address Validation](https://www.devkult.com/regex/ipv4.md)
- [Regex for URL Slug Validation](https://www.devkult.com/regex/slug.md)

Open the interactive page: https://www.devkult.com/regex/uuid