T
ToolPrime

Regex for UUID

Validates UUIDs (versions 1-5) in standard format.

Pattern

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

Live Tester

Enter a string to test

Examples

550e8400-e29b-41d4-a716-446655440000
6ba7b810-9dad-11d1-80b4-00c04fd430c8
550e8400-e29b-61d4-a716-446655440000
not-a-uuid

Pattern Breakdown

[0-9a-f]{8} — 8 hex chars

[0-9a-f]{4} — 4 hex chars

[1-5][0-9a-f]{3} — version digit + 3 hex

[89ab][0-9a-f]{3} — variant digit + 3 hex

[0-9a-f]{12} — 12 hex chars

Code Snippets

Javascript

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test("550e8400-e29b-41d4-a716-446655440000"); // true

Python

bool(re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", "550e8400-e29b-41d4-a716-446655440000", re.I))  # True

Php

preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i', "550e8400-e29b-41d4-a716-446655440000"); // 1

Related Patterns