GUID Regex Patterns - Validation & Best Practices

Common regex patterns for validating GUID / UUID input. Learn about canonical, versioned, and flexible regexes for input validation, and best practices for using regex with GUIDs / UUIDs.

Important: Regex can validate the format, but it cannot guarantee uniqueness, security or that a GUID / UUID was generated correctly. For strict validation, always parse using a trusted library.

Canonical GUID / UUID (hyphenated)

Matches the standard 8-4-4-4-12 representation with hex digits (case-insensitive).

^[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}$

Canonical + version (1-8) + RFC variant (8/9/a/b)

Enforces that the GUID / UUID is one of the modern versions (1 through 8) and uses the standard RFC variant (8, 9, a, or b).

^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$

Accept common input variants (braces and URN)

Accepts any of these forms: uuid, {uuid}, or urn:uuid:uuid. Useful for UI input fields where users paste different styles.

^(?:urn:uuid:)?(?:\{[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}\}|[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})$

Empty GUID / Nil UUID (all zeros)

Sometimes you want to explicitly detect an Empty GUID / Nil UUID.

^00000000-0000-0000-0000-000000000000$

Practical notes

  • Normalize first: trim whitespace, optionally strip urn:uuid: and braces, then validate.
  • Prefer parsing in code: use your platform's UUID/GUID parser after regex checks to avoid edge cases.
  • Version and variant are separate: version is the first hex digit of the third group; variant is the first hex digit of the fourth group.
  • Don't over-constrain input: if your app accepts uppercase or braces, reflect that in validation and normalization, not in your database storage.

Try our GUID / UUID Validator to validate, decode & analyze your input.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.