tools / regex library / uuid
regex pattern · ready to copy

Regex for matching UUIDs (v1-v5)

Match canonical UUID with hyphens. Version-agnostic.

intermediate javascript / pcre / python4 use cases

The 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}

Test cases

InputResult
550e8400-e29b-41d4-a716-446655440000matches
f47ac10b-58cc-4372-a567-0e02b2c3d479matches
550e8400e29b41d4a716446655440000 (no hyphens)rejects
not-a-uuidrejects

Edge cases & caveats

Strict version: replace `[1-5]` with the version digit you want. UUID v7 (time-ordered, 2024+) starts with `7` not `[1-5]` — extend to `[1-5,7]` if you need v7 too.

Common use cases

Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab  

Related

url · mac address · semver version · twitter handle · ↗ generate realistic test names