Skip to main content
hank-builds.com

UUID regex

Matches UUID/GUID format.

/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi

What it matches

The canonical 8-4-4-4-12 hexadecimal form, hyphen separated, with the i flag so both spellings match. That is the textual representation defined by RFC 4122 and the one produced by crypto.randomUUID() and by every database UUID column.

Railroad diagram

Read left to right. Every path through the diagram is a string the pattern accepts.

{8} [0-9a-f] "-" {4} [0-9a-f] "-" {4} [0-9a-f] "-" {4} [0-9a-f] "-" {12} [0-9a-f]

Drag to pan. Ctrl+scroll to zoom.

Breakdown

gFind all matches instead of stopping after the first
iLetters match both upper and lower case
[0-9a-f]{8}Match one of: Literal "0"–Literal "9", Literal "a"–Literal "f", exactly 8 times
-Literal "-"
[0-9a-f]{4}Match one of: Literal "0"–Literal "9", Literal "a"–Literal "f", exactly 4 times
-Literal "-"
[0-9a-f]{4}Match one of: Literal "0"–Literal "9", Literal "a"–Literal "f", exactly 4 times
-Literal "-"
[0-9a-f]{4}Match one of: Literal "0"–Literal "9", Literal "a"–Literal "f", exactly 4 times
-Literal "-"
[0-9a-f]{12}Match one of: Literal "0"–Literal "9", Literal "a"–Literal "f", exactly 12 times

Test cases

Matches

  • 550e8400-e29b-41d4-a716-446655440000
  • 123e4567-e89b-12d3-a456-426614174000
  • F47AC10B-58CC-4372-A567-0E02B2C3D479

Does not match

  • 550e8400e29b41d4a716446655440000
  • 550e8400-e29b-41d4-a716-44665544
  • not-a-uuid

Caveats

It checks shape, not version. The version and variant bits live in the third and fourth groups and this pattern ignores both, so it accepts strings no generator would produce. It also rejects the braced {…} and urn:uuid: forms, and the 32-character unhyphenated spelling some APIs return.

More common patterns

Test this against your own input in the regex tester, browse the full pattern library, or check the syntax cheat sheet.