PatternRegex

Match any UUID

Match the 8-4-4-4-12 hex shape shared by every UUID version, for code paths that just need to recognize an identifier, not enforce its version.

Last updated

Patterngi
\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
Open in Regex Tester & Builder

Matches

  • id 123e4567-e89b-12d3-a456-426614174000 was issued
  • ID f47AC10B-58CC-4372-A567-0E02B2C3D479 works too

Doesn’t match

  • not-a-uuid-at-all-nope
  • 123e4567-e89b-12d3-a456-42661417400

Why it’s written this way

The five hex groups of length 8-4-4-4-12, joined by literal hyphens, are the one thing every UUID version has in common — this pattern deliberately stops there instead of pinning down the version nibble or the variant bits.

That is the key difference from a v4-only pattern, which additionally locks the first character of the third group to '4' and constrains the first character of the fourth group to 8, 9, a or b. Use this looser pattern when you need to recognize 'something UUID-shaped' from any generator; use the v4 pattern when you specifically need to enforce that a client sent a v4 id.

Edge cases to know

  • It accepts version and variant bits that don't correspond to any assigned UUID version — the all-zero nil UUID and made-up strings like ffffffff-ffff-ffff-ffff-ffffffffffff both match.
  • It has no opinion on braces or the urn:uuid: prefix some systems wrap UUIDs in — strip those separately if present.
  • Case-insensitivity means it treats uppercase and lowercase hex as equivalent, even though most systems normalize to one case internally.

Related in Patterns