DevKits

Validation

Match a UUID (v4)

Flags: gi

Validate or extract UUIDs (any version, or specifically v4).

Pattern

Regular expression

[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}

How it works

This checks canonical UUID hyphenation and constrains the version (`[1-5]`) and variant (`[89ab]`) nibbles as per RFC 4122. To accept any version, replace `[1-5]` with `[0-9a-f]`.

Matches

  • 550e8400-e29b-41d4-a716-446655440000
  • 9F1A0B7E-3F0C-4B0D-9A7B-6E2F0C1D2E3F

Non-matches

  • 550e8400e29b41d4a716446655440000 (no hyphens)
  • not-a-uuid
  • 550e8400-e29b-71d4-a716-446655440000 (invalid version 7 nibble)

Common gotchas

UUID v7 (time-ordered) uses version nibble 7. If you need to accept v7, expand the version class to `[1-7]`. Also, UUIDs are case-insensitive — always use the `i` flag.

Language snippets

JavaScript

const re = /[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gi;

Python

re.findall(r"[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", text, re.I)

Go

re := regexp.MustCompile(`(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)

Java

Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", Pattern.CASE_INSENSITIVE)

Frequently asked questions

What is the regex for UUID (v4)?

The pattern [0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12} (flags: gi) matches UUID (v4). This checks canonical UUID hyphenation and constrains the version (`[1-5]`) and variant (`[89ab]`) nibbles as per RFC 4122. To accept any version, replace `[1-5]` with `[0-9a-f]`.

What does this UUID (v4) pattern match?

It matches strings like 550e8400-e29b-41d4-a716-446655440000, 9F1A0B7E-3F0C-4B0D-9A7B-6E2F0C1D2E3F, but rejects 550e8400e29b41d4a716446655440000 (no hyphens), not-a-uuid.

How do I use this pattern in JavaScript, Python, Go, Java?

Ready-to-run snippets are provided for JavaScript, Python, Go, Java. Copy the one for your language from the Language snippets section — each wraps the same core pattern in that language's regex API.

What are common pitfalls with a UUID (v4) regex?

UUID v7 (time-ordered) uses version nibble 7. If you need to accept v7, expand the version class to `[1-7]`. Also, UUIDs are case-insensitive — always use the `i` flag.

Related patterns

Try this pattern in a tool

Try any pattern live in the Regex Tester