Regex for UUID (GUID)
A UUID is 32 hexadecimal digits written in five groups of 8, 4, 4, 4 and 12 characters separated by dashes. This pattern matches that canonical layout.
The pattern
/\b[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}\b/gThe tester opens with this pattern and the examples below already loaded. Nothing you type is uploaded.
How it works
[0-9a-fA-F]{8}- First group: eight hex digits.
-[0-9a-fA-F]{4}- Three middle groups of four hex digits, each after a dash.
-[0-9a-fA-F]{12}- Last group: twelve hex digits.
Examples
Matches
123e4567-e89b-12d3-a456-426614174000550e8400-e29b-41d4-a716-446655440000
Does not match
123e4567-e89b-12d3-a456-42661417400not-a-uuid123e4567e89b12d3a456426614174000
Use it in JavaScript
const re = /\b[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}\b/g;
// Find every match in a block of text
const found = text.match(re);
// Validate that a whole value matches (no stray characters around it)
const exact = new RegExp('^(?:' + re.source + ')$', re.flags.replace('g', ''));
const isValid = exact.test(value);Limits and tips
- It does not check the version or variant digits. For version 4 only, use [0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12} with the i flag.
- UUIDs written without dashes, or wrapped in braces, need small changes to the pattern.
Frequently asked questions
How long is a UUID as a string?
Thirty-six characters: 32 hex digits plus four dashes.
Does the regex check the UUID version?
No. Use the version-4 variant in the notes if you need to restrict it.