Regex to Validate UUIDs

Validate UUID format (versions 1-7) with this regex. Matches standard 8-4-4-4-12 hexadecimal format with version check. Free tool.

Regular Expression

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

Token Breakdown

TokenDescription
^Anchors at the start of the string (or line in multiline mode)
[0-9a-f]Character class — matches any one of: 0-9a-f
{8}Matches exactly 8 times
-Matches the literal character '-'
[0-9a-f]Character class — matches any one of: 0-9a-f
{4}Matches exactly 4 times
-Matches the literal character '-'
[1-7]Character class — matches any one of: 1-7
[0-9a-f]Character class — matches any one of: 0-9a-f
{3}Matches exactly 3 times
-Matches the literal character '-'
[89ab]Character class — matches any one of: 89ab
[0-9a-f]Character class — matches any one of: 0-9a-f
{3}Matches exactly 3 times
-Matches the literal character '-'
[0-9a-f]Character class — matches any one of: 0-9a-f
{12}Matches exactly 12 times
$Anchors at the end of the string (or line in multiline mode)

Detailed Explanation

This regex validates Universally Unique Identifiers (UUIDs) in their standard string representation. Here is the token-by-token breakdown:

^ — Anchors the match at the start of the string.

[0-9a-f]{8} — Matches the first group of exactly eight hexadecimal digits. UUIDs use lowercase hex digits (though the i flag makes this case-insensitive).

  • — Matches a literal hyphen separator between groups.

[0-9a-f]{4} — Matches the second group of exactly four hex digits.

  • — Another hyphen separator.

[1-7] — Matches the version digit. This is the first digit of the third group and indicates the UUID version. Valid versions are 1 through 7, covering time-based (v1), DCE security (v2), MD5 hash (v3), random (v4), SHA-1 hash (v5), sortable time-based (v6), and Unix epoch time-based (v7).

[0-9a-f]{3} — Matches the remaining three hex digits of the third group.

  • — Another hyphen separator.

[89ab] — Matches the variant digit. The first digit of the fourth group indicates the UUID variant. Values 8, 9, a, or b indicate the standard RFC 4122 variant.

[0-9a-f]{3} — Matches the remaining three hex digits of the fourth group.

  • — Another hyphen separator.

[0-9a-f]{12} — Matches the fifth and final group of exactly twelve hex digits.

$ — Anchors the match at the end.

The i flag makes matching case-insensitive, accepting both uppercase and lowercase hex digits. This pattern is essential for validating UUIDs in APIs, databases, and distributed systems.

Example Test Strings

InputExpected
550e8400-e29b-41d4-a716-446655440000Match
6ba7b810-9dad-11d1-80b4-00c04fd430c8Match
not-a-uuid-at-all-nopeNo Match
550e8400-e29b-01d4-a716-446655440000No Match
F47AC10B-58CC-4372-A567-0E02B2C3D479Match

Try It — Interactive Tester

//i
gimsuy
No matches found.
Pattern: 73 charsFlags: iMatches: 0

Ctrl+Shift+C to copy regex

Customize this pattern →