~/regex-tester

Match UUIDs with regex

A regex that matches UUID v4 specifically (and a general one for any version) with the version + variant bits in the right places.

# pattern

/\b[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/gi

→ Open in regex tester (pre-filled)

# how it works

UUID v4 has fixed bits: the 13th hex character is always 4 (the version), and the 17th must be 8, 9, a, or b (the variant). The pattern above enforces both. For any UUID version, replace `4` with `[1-5]` and `[89ab]` with `[89ab0-9]`.

# sample input

Real v4: 550e8400-e29b-41d4-a716-446655440000. Real v1: a8098c1a-f86e-11da-bd1a-00112444be1e. Fake: 00000000-0000-0000-0000-000000000000.

# pitfalls

# other patterns