Regex for UUID v4

All patterns
Validation69 chars · /i

Regex for UUID v4

UUID v4 patterns help validate request IDs, webhook event IDs, and client-generated identifiers without accepting the wrong version bit.

The expression

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

How to read it

Anchor: the match must start at the beginning of the string.

Anchor: the match must run to the end of the string.

A brace quantifier fixes how many times the previous token repeats.

iignore case

Validate your own text, line by line

no input
Try:

This expression is anchored, so it asks whether a whole string is valid. Each line above is tested on its own — it will not find a match inside a longer sentence.

Examples, checked in your browser

4/4 verified

550e8400-e29b-41d4-a716-446655440000

Matches.

987fbc97-4bed-4078-8f07-9141ba07c9f3

Matches.

550e8400-e29b-11d4-a716-446655440000

No match — this is the kind of input the pattern rejects.

not-a-uuid

No match — this is the kind of input the pattern rejects.

Use it in code

3 languages
JavaScript
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
regex.test(input);
Python
import re
pattern = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", re.IGNORECASE)
bool(pattern.search(input))
Go
re := regexp.MustCompile("(?i)^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")
matched := re.MatchString(input)

Other validation patterns

6
GroupValidation
Flags/i
Examples4
SafetyOK