Wiki GUID / UUID Regex Patterns - Validation & Best Practices GUID / UUID 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 Inspector to validate your input.
Learn more These articles expand on related concepts, formats and practical considerations.
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 / UUID specifications, RFCs, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and third-party 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 documentation (such as RFC 4122, RFC 9562 and vendor-specific references). Always evaluate behavior in your own environment.