Skip to content

UUID Regex Tester

Match the standard 36-character UUID text form, in any version and either case. Read on to narrow it to one version.

JavaScript
412 characters

One case per line; the m flag makes ^ and the end anchor work line by line.

Link optionspattern only

The address bar holds the pattern, flags and replacement, so Copy link shares them. Your test text stays out of it unless you include it (up to 2,000 characters), because it may be private. Nothing is sent to a server.

Matches

5matches

The first is “f81d4fae-7dec-11d0-a765-00a0c91e6bf6”, at position 0.

Groups
none
Characters matched
180 of 412
What the pattern meansHover or tap a part to see it in the pattern and what it matched
How this works: Method, 5 sources, Checked against 1 worked example,

How this works

Method

Your pattern runs in your own browser’s JavaScript engine, in a background worker that is stopped after 1.5 seconds, so a pattern that backtracks catastrophically can’t freeze the page. The explanation comes from our own parser of the ECMAScript pattern grammar, checked against the engine; what each part matched is found by wrapping that part in one more group and running the pattern again. Conversions to other flavours only rewrite the syntax and list what their documentation says works differently.

How it’s tested

One worked example for this page is checked by automated tests before every release: given the inputs, the tool must show the expected answer.

Changes

  • First published, with a library of 19 common patterns and their test cases.

How we make toolsReport a mistake

Worked example

Take f81d4fae-7dec-11d0-a765-00a0c91e6bf6, the first case in the tester. Reading the pattern left to right, each part takes its share of the text:

  1. ^The start of the text (matches a position, no characters)
  2. [0-9a-f]{8}Exactly eight characters, each 0–9 or a–f (either case) matches f81d4fae
  3. -“-” matches -
  4. [0-9a-f]{4}Exactly four characters, each 0–9 or a–f (either case) matches 7dec
  5. -“-” matches -
  6. [0-9a-f]{4}Exactly four characters, each 0–9 or a–f (either case) matches 11d0
  7. -“-” matches -
  8. [0-9a-f]{4}Exactly four characters, each 0–9 or a–f (either case) matches a765
  9. -“-” matches -
  10. [0-9a-f]{12}Exactly 12 characters, each 0–9 or a–f (either case) matches 00a0c91e6bf6
  11. $The end of the text (matches a position, no characters)

How the UUID regex works

A UUID is 128 bits written as 32 hex digits in five groups of 8, 4, 4, 4 and 12, joined by hyphens, 36 characters in all. The pattern spells out exactly that: [0-9a-f]{8}, then three groups of [0-9a-f]{4}, then [0-9a-f]{12}, each separated by a literal hyphen. The i flag accepts GUIDs printed in upper case.

It accepts every version on purpose, including the special Nil and Max values. The version is the first digit of the third group, so to accept only random version 4 UUIDs, change that group to 4[0-9a-f]{3}; for version 7, use 7[0-9a-f]{3}.

The variant sits in the first digit of the fourth group. For the standard variant it is 8, 9, a or b, so a strict v4 check also turns that group into [89ab][0-9a-f]{3}.

Test cases

Every case runs as an automated test of this page’s pattern, so the table can’t drift from what the pattern really does.

Test cases for the UUID regex
TextResultWhy
f81d4fae-7dec-11d0-a765-00a0c91e6bf6Passesthe example in RFC 9562, a version 1 UUID
36b8f84d-df4e-4d49-b662-bcde71a8764fPassesa random version 4 UUID
01928f3a-7b2c-7d4e-9f10-a1b2c3d4e5f6Passesa time-ordered version 7 UUID
00000000-0000-0000-0000-000000000000Passesthe Nil UUID
FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFFPassesthe Max UUID, upper case
{f81d4fae-7dec-11d0-a765-00a0c91e6bf6}Failscurly braces, the Windows registry style
f81d4fae7dec11d0a76500a0c91e6bf6Failsno hyphens
f81d4fae-7dec-11d0-a765-00a0c91e6bfFailseleven digits in the last group
urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6Failsthe URN prefix
f81d4fae-7dec-11d0-a765_00a0c91e6bf6Failsan underscore instead of a hyphen
g81d4fae-7dec-11d0-a765-00a0c91e6bf6Failsg is not a hex digit

What it doesn’t check

  • A valid format says nothing about uniqueness or where the value came from; it only proves the string looks like a UUID.
  • Braces, a urn:uuid: prefix or the 32-digit form without hyphens are common in other systems; strip or add them before testing.
  • The broad pattern accepts version digits 0 and 9 to f, which no standard defines; use the version-specific form when you need a real UUID of a known kind.

The same pattern in other languages

Converted automatically from the JavaScript version; the tester above always runs JavaScript.

The pattern in Python, PCRE, Go, Java and .NET
FlavourPatternNotes
Python(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\Z
PCRE(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z
Go(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
Java(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z
.NET(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z

Sources

Frequently Asked Questions

Is a GUID the same as a UUID?

Yes. GUID is Microsoft’s name for the same 128-bit identifier and uses the same 8-4-4-4-12 layout, often in upper case and sometimes in braces. Remove the braces and this pattern accepts it.

How do I check that a UUID is version 4?

Require the first digit of the third group to be 4 and the first digit of the fourth group to be 8, 9, a or b. Everything else stays the same.

Should I lower-case UUIDs before storing them?

Yes. The same UUID can arrive in either case, and storing one form means a plain string comparison finds duplicates. Databases with a native UUID type do this for you.