Python (re)

UUID (v1–v5) in PY

Match RFC 4122 UUIDs (versions 1–5) in the standard 8-4-4-4-12 hex format.

Try it in the PY tester →

Pattern

regexPY
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}   (flags: gi)

Python (re) code

pyPython
import re

pattern = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", re.IGNORECASE)
input_text = "550e8400-e29b-41d4-a716-446655440000"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

The version nibble [1-5] and the variant bits [89ab] are constrained per RFC 4122. Matching is case-insensitive since UUIDs may be upper or lowercase.

Examples

Input

550e8400-e29b-41d4-a716-446655440000

Matches

  • 550e8400-e29b-41d4-a716-446655440000

Input

6ba7b810-9dad-11d1-80b4-00c04fd430c8

Matches

  • 6ba7b810-9dad-11d1-80b4-00c04fd430c8

Same pattern, other engines

← Back to UUID (v1–v5) overview (all engines)