RegexBuilder · regex answers
Regex for a UUID
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iA canonical UUID is 8-4-4-4-12 hex digits. The third group starts with the version digit and the fourth with the variant nibble, which is 8, 9, a or b for the variant every common library emits. Versions 1 through 8 are defined today.
What each part does
| [0-9a-f]{8} | the first group, eight hex digits |
| [1-8] | the version digit |
| [89ab] | the variant nibble |
| i | case-insensitive, since UUIDs are printed in both cases |
Tested against real input
Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.
| Input | Result | Matched |
|---|---|---|
| 550e8400-e29b-41d4-a716-446655440000 | matches | 550e8400-e29b-41d4-a716-446655440000 |
| 01890a5d-ac96-774b-bcce-b302099a8057 | matches | 01890a5d-ac96-774b-bcce-b302099a8057 |
| 550e8400-e29b-41d4-a716-44665544000 | no match | — |
| 550e8400e29b41d4a716446655440000 | no match | — |
| 550e8400-e29b-01d4-a716-446655440000 | no match | — |
The mistake to avoid
Accepting the nil UUID 00000000-0000-0000-0000-000000000000 by using [0-9a-f]{4} for every group — it is a valid identifier but almost never a valid value in your system.
Try it on your own text
Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.
Open RegexBuilderOther regex answers
- Regex for an email address
- Regex for a US phone number
- Regex for an IPv4 address
- Regex for a URL
- Regex for a date in YYYY-MM-DD format
- Regex to match digits only
- Regex for alphanumeric characters
- Regex to find special characters
- Regex for a strong password
- Regex to match whitespace
- Regex to trim leading and trailing whitespace
- Regex for a hex colour code