Regex for UUID

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

Options
Matches

Examples

Note

Checks the version digit (1–8) and the RFC 9562 variant bits (8, 9, a or b). Drop those two checks to accept any 8-4-4-4-12 hex string.

Matches in the example

  • "550e8400-e29b-41d4-a716-446655440000"
  • "01890a5d-ac96-774b-bcce-b302099a8057"

Token by token

  1. \b a word boundary
  2. [0-9a-f]{8} one of: “0” to “9” or “a” to “f”, exactly 8 times
  3. - the character “-”
  4. [0-9a-f]{4} one of: “0” to “9” or “a” to “f”, exactly 4 times
  5. - the character “-”
  6. [1-8] one of: “1” to “8”
  7. [0-9a-f]{3} one of: “0” to “9” or “a” to “f”, exactly 3 times
  8. - the character “-”
  9. [89ab] one of: “8”, “9”, “a” or “b”
  10. [0-9a-f]{3} one of: “0” to “9” or “a” to “f”, exactly 3 times
  11. - the character “-”
  12. [0-9a-f]{12} one of: “0” to “9” or “a” to “f”, exactly 12 times
  13. \b a word boundary

Other patterns