Formatuuid regex

UUID v4 regex

RFC 4122 UUID version 4 — the random-bytes variant nearly every database uses.

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

What it matches

A UUID v4 is 128 bits of randomness shaped like `xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx`, where `M` is always `4` (the version) and the first hex of `N` is always `8`, `9`, `a`, or `b` (the variant). This pattern enforces both. If you only need to check 'is this a UUID-shaped string' without caring about the version, swap `4[0-9a-f]{3}` for `[0-9a-f]{4}` and `[89ab][0-9a-f]{3}` for `[0-9a-f]{4}`.

Examples

Matches

  • c5e0a8b6-5cf7-4f3e-9c20-3a3b56b0e0bd

    8-4-4-4-12 hex layout with `4` version and `9` variant bit.

  • 550E8400-E29B-41D4-A716-446655440000

    Uppercase hex is fine because the `i` flag is on.

Does not match

  • 550e8400-e29b-11d4-a716-446655440000

    Version digit is `1`, not `4` — this is a v1 UUID.

  • 550e8400-e29b-41d4-c716-446655440000

    Variant bit is `c`, which is reserved for Microsoft GUIDs.

  • 550e8400e29b41d4a716446655440000

    Missing hyphens.

  • 12345

    Wrong shape entirely.

Edge cases & gotchas

  • Will NOT match UUID v1, v3, v5, v6, or v7 — those have different version digits. If you need to accept any version, use `[0-9a-f]` in place of `4` and `[0-9a-f]` in place of `[89ab]`.
  • Hyphens are required exactly where shown — UUIDs without hyphens (raw hex form) don't match. Add `?` after each `-` if you want both forms.
  • Doesn't reject the all-zero UUID (`00000000-0000-4000-8000-000000000000`). That's a valid v4 UUID by spec but usually means a bug.
  • Doesn't check Unicode normalization — Greek lookalikes (`Α` vs `A`) won't match, which is what you want.

In your language

// JavaScript
const re = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const match = "input".match(re);

All 13 languages (including Bash, Perl, Kotlin, Swift) available in the full toolkit Export tab.

Notes for production

  • ULIDs and KSUIDs are NOT UUIDs and won't match this pattern. They have their own formats (base32 / base62, different lengths).
  • If you're generating UUIDs in JS, `crypto.randomUUID()` produces v4 since Node 18 and is the right call for anything new.

Frequently asked

How do I match any UUID version, not just v4?

Replace `4[0-9a-f]{3}` with `[0-9a-f]{4}` and `[89ab][0-9a-f]{3}` with `[0-9a-f]{4}`. You'll lose the version-specific validity check but match v1 through v7.

Does the UUID need to be lowercase?

No — the `i` flag makes the pattern case-insensitive. Both `abcdef` and `ABCDEF` hex match.

Why doesn't my UUID match?

Most common causes: it's not actually v4 (check the version digit), or it has braces / surrounding whitespace (some Windows tools wrap UUIDs in `{...}` — strip those first).

Related patterns