UUID Regex Python Validator

Search...

⌘K

UUID Regex Python Validator

Search...

⌘K


UUID Regex Python Validator

UUID Regex Python Validator

Validate UUID strings with the UUID Regex Python Validator built for Python developers working on secure APIs, databases, and distributed systems. This tool checks whether your identifiers conform to the standard UUID format using Python regex. For full validation suites, pair it with the Email Regex Python Validator or IP Address Regex Python Validator to strengthen your backend input checks.

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
Match 1: "deadbeef-7331-4123-8123-ba5eba11babe" at index 0
Test your APIs today!

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

Regular Expression - Documentation

What is UUID Regex?


A UUID (Universally Unique Identifier) is a 128-bit identifier used to uniquely label data across systems. It’s typically represented as 32 hexadecimal characters split into 5 groups by hyphens, like:


123e4567-e89b-12d3-a456-426614174000

UUIDs are used in databases, APIs, microservices, IoT, and any context requiring global uniqueness.


UUID Regex Pattern in Python


To match a standard UUID format (v1–v5), use this regex pattern:


^[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 pattern checks:

  • 8 hexadecimal characters

  • 4-digit version group (starting with 1–5)

  • 4-digit variant group (starting with 8–b)

  • Final 12 hex digits


How to Validate UUIDs Using Regex in Python


Here’s how to use the re module in Python to match valid UUIDs:


import re

def is_valid_uuid(uuid_str):
    pattern = re.compile(r'^[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}$')
    return bool(pattern.match(uuid_str))

# Example test
uuids = [
    "123e4567-e89b-12d3-a456-426614174000",  # Valid
    "123e4567e89b12d3a456426614174000",      # Invalid (no hyphens)
    "ZZZe4567-e89b-12d3-a456-426614174000"   # Invalid (non-hex)
]

for u in uuids:
    print(f"{u} -> {is_valid_uuid(u)}")


Use Cases


  • API Resource Identification: Use UUIDs in REST endpoints or JSON payloads to reference records uniquely.

  • Database Indexing: Use UUIDs as primary keys to prevent collision across distributed tables.

  • Session Management: Validate UUID-based tokens for user sessions in secure applications.

  • Form Submissions: Check if hidden fields in forms pass valid UUIDs.

  • Combine with Password Regex Python Validator to secure user login data.


Pro Tips


  • UUIDs can be lowercase or uppercase, and this pattern matches both.

  • Use Python’s uuid module to generate and compare UUIDs, and validate format with this regex.

  • This regex only checks the format, not the UUID’s randomness or version logic.

  • Normalize UUIDs to lowercase using .lower() before storage for consistency.

  • Combine with the Email Regex Python Validator or Phone Number Regex Python Validator for full form validation in Python apps.


Frequently asked questions

What UUID versions does this regex support?×
This pattern supports UUID versions 1 to 5 by checking the version digit.
Can I use this regex to validate UUIDs in uppercase?+
Is this format suitable for database keys?+
What happens if a UUID has no hyphens?+
Can this regex detect invalid UUID version numbers?+