Utilo

UUID Regular Expression – Free, Online, Private

Matches the 8-4-4-4-12 UUID text form and checks the version and variant nibbles.

Tester
Sample
Matches (1)
  • 550e8400-e29b-41d4-a716-446655440000

The pattern

A UUID is 32 hex digits in five groups. This pattern also checks the version nibble, the first digit of the third group, which must be 1 through 8, and the variant nibble, the first digit of the fourth group, which must be 8, 9, a, or b for the RFC 4122 layout. The sample's first id matches. The second has a version nibble of 0 and does not. Nil UUIDs and future versions outside 1–8 are rejected on purpose.

The source is [0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}. The flags on this page are i. i means case-insensitive. m means ^ and $ match at line breaks, which is how the sample can show several candidates. g is not set. The tester finds non-overlapping matches, and without g a pattern with no anchor still reports the matches it walks. The box under the title is a tester with this pattern and the sample already filled in. Edit either one. Nothing you type is uploaded. The same tester, without a preset, is the regex tool.

How to read it

Each {8}, {4}, or {12} is a count of hex digits. The hyphens are literal. [1-8] is the version. Versions 1 through 8 cover the time-based, name-based, random, and the newer Unix-time forms people actually ship, including version 7. [89abAB] is the variant. The i flag lets the rest of the digits be either case. The pattern does not capture the groups. Wrap parentheses around a piece if you need the version digit in a group. Add ^ and $ when the field must contain nothing else.

What it will not do

The pattern does not checksum a UUID. Random ids do not have a checksum. It does not require the canonical lowercase form. It will match a UUID glued to a word if you skip boundaries. It will not match the URN prefix urn:uuid:. Strip that prefix or make it optional. Braced GUIDs of the form {8-4-4-4-12} need optional braces. They are not in this pattern, because a brace in a log usually means something else.

A match is not a parsed value. An email pattern does not send mail, a UUID pattern does not allocate an id, and a password pattern does not store a password. When the next step needs a real parser, use one: the URL constructor, a date library, a semver library, or the converters on this site. The expression is the part you can see.

JavaScript, Python, and Go

The JavaScript snippet uses the RegExp constructor so the source does not have to be escaped for a literal slash. The Python snippet uses a normal string with the same escapes JSON would emit, which keeps \d as a regex digit class. Go's snippet uses a raw string. If the pattern contains a lookahead, the Go snippet says so and does not call MustCompile, because RE2 would reject it at runtime.

JavaScriptconst re = new RegExp("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}", "i");
const found = text.match(re);
console.log(found ? found[0] : "no match");
Pythonimport re

pattern = re.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}", re.IGNORECASE)
found = pattern.search(text)
print(found.group(0) if found else "no match")
Gopackage main

import (
	"fmt"
	"regexp"
)

func main() {
	text := ""
	re := regexp.MustCompile(`(?i)[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}`)
	fmt.Println(re.FindString(text))
}

Frequently asked questions

Does version 7 match?

Yes. The version nibble allows 1 through 8, which includes 7.

Why is the all-zero UUID rejected?

Its version nibble is 0, which is outside 1–8. Allow [0-9a-f] in that position if you must accept the nil UUID.

Are braces included?

No. The pattern is the hyphenated hex form only.

Does case matter?

No. The i flag and the classes accept both cases.