GUID Regex Python Validator

Search...

⌘K

GUID Regex Python Validator

Search...

⌘K


GUID Regex Python Validator

GUID Regex Python Validator

The GUID Regex Python Validator is designed to help developers and testers confirm that GUIDs (Globally Unique Identifiers) match proper formatting. Perfect for validating API tokens, resource IDs, or database keys, this tool is essential for quality checks. You can pair it with the UUID Regex Python Validator or the Mac Address Regex Python Validator to build solid validation flows in your Python projects.

deadbeef-7331-4123-8123-ba5eba11babe
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

What Is a GUID?


A GUID is a 128-bit unique identifier often used to label resources like users, sessions, or records. It appears as a string in this format:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Where each x is a hexadecimal digit (0-9, a-f, or A-F). While GUIDs and UUIDs are functionally similar, GUIDs are more common in Microsoft-based systems.


Regex Pattern for GUID in Python


Here’s a regex pattern that accurately validates a standard GUID:

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


This ensures:

  • 8 digits at the beginning

  • Followed by three groups of 4 digits (hyphen-separated)

  • Ends with 12 hex digits


Python Example to Validate GUID


import re

def is_valid_guid(guid):
    pattern = re.compile(
        r'^[0-9a-fA-F]{8}-'
        r'[0-9a-fA-F]{4}-'
        r'[1-5][0-9a-fA-F]{3}-'
        r'[89abAB][0-9a-fA-F]{3}-'
        r'[0-9a-fA-F]{12}$'
    )
    return bool(pattern.fullmatch(guid))

# Test GUIDs
test_guids = [
    "123e4567-e89b-12d3-a456-426614174000",
    "00112233-4455-6677-8899-aabbccddeeff",
    "invalid-guid-format"
]

for g in test_guids:
    print(f"{g} -> {is_valid_guid(g)}")


Use Cases


  • Database Record IDs: Use GUIDs as primary keys for distributed systems.

  • Authentication Tokens: Validate GUIDs passed via API headers or query strings.

  • Data Synchronization: Match GUIDs in local and remote storage to ensure consistency.

  • Debugging Tools: Use it with the IP Address Regex Python Validator to monitor network-based identifiers.


Pro Tips


  • Always sanitize GUID inputs—especially from client-side sources.

  • Strip leading/trailing whitespaces before validation.

  • Combine it with the Date Regex Python Validator when working with time-stamped identifiers.

  • Use lowercase GUIDs in systems where case doesn’t matter to maintain consistency.


Frequently asked questions

What’s the difference between a GUID and a UUID?×
Functionally, they are similar. UUID is the official standard, while GUID is Microsoft’s term for the same thing.
Can this regex detect invalid or duplicate GUIDs?+
What versions of GUID does this support?+
Does case matter in GUIDs?+
Is this suitable for database validation?+