New blogMaking an AI Agent You Can Trust With Money

★ Dev formats · regex

Regex for UUID

Matches hyphenated UUIDs of versions 1 to 8 (including v4 random and v7 time-ordered) with the RFC variant. The nil and max UUIDs (all zeros or all f's) are special values and don't pass.

  • Runs in your browser
  • No signup

Try the uuid pattern

Read it in plain English (best-effort)

  • ^start of a line
  • [0-9a-fA-F]one character from: 0–9, a–f, A–F
  • {8}exactly 8 of the previous
  • -the character '-'
  • [0-9a-fA-F]one character from: 0–9, a–f, A–F
  • {4}exactly 4 of the previous
  • -the character '-'
  • [1-8]one character from: 1–8
  • [0-9a-fA-F]one character from: 0–9, a–f, A–F
  • {3}exactly 3 of the previous
  • -the character '-'
  • [89abAB]one character from: '8', '9', 'a', 'b', 'A', 'B'
  • [0-9a-fA-F]one character from: 0–9, a–f, A–F
  • {3}exactly 3 of the previous
  • -the character '-'
  • [0-9a-fA-F]one character from: 0–9, a–f, A–F
  • {12}exactly 12 of the previous
  • $end of a line

One sample per line works well with the m flag on anchored patterns.

Waiting for a pattern
01

The pattern, piece by piece

/^[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}$/
Pattern explanation
PartWhat it does
[0-9a-fA-F]{8}8 hex digits
-[0-9a-fA-F]{4}4 hex digits
-[1-8][0-9a-fA-F]{3}the version digit (1–8) then 3 hex digits
-[89abAB][0-9a-fA-F]{3}the variant: first digit 8, 9, a or b
-[0-9a-fA-F]{12}12 hex digits
02

What it accepts and rejects

Every sample below is checked automatically in JavaScript and Python. The tester above is preloaded with all of them, one per line.

Should match
Should match
123e4567-e89b-12d3-a456-426614174000✓
550e8400-e29b-41d4-a716-446655440000✓
f47ac10b-58cc-4372-a567-0e02b2c3d479✓
018f3b1e-7c3a-7d4e-9f00-1a2b3c4d5e6f✓
6BA7B810-9DAD-11D1-80B4-00C04FD430C8✓
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11✓
Should not match
Should not match
123e4567e89b12d3a456426614174000✗
123e4567-e89b-02d3-a456-426614174000✗
123e4567-e89b-12d3-c456-426614174000✗
00000000-0000-0000-0000-000000000000✗
g23e4567-e89b-12d3-a456-426614174000✗
{123e4567-e89b-12d3-a456-426614174000}✗
03

Copy it into your code

RE2-safeNo lookarounds or backreferences, so the same pattern works in Go's RE2 engine and in Rust's regex crate.

const uuidRe = /^[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}$/;

export function isValidUuid(value) {
  return uuidRe.test(value.trim());
}
04

When not to use regex for this

If you only need 'is this a UUID my code can parse', use your UUID library's parser. In Postgres, a uuid column rejects bad values for free.

05

Questions engineers actually ask

Does it match UUID v7?
Yes. Version digits 1 through 8 are accepted, which covers v7's time-ordered IDs.
Why doesn't the nil UUID match?
00000000-0000-0000-0000-000000000000 has version 0, a special value rather than a generated ID. Add it explicitly if your system uses it.
What is catastrophic backtracking?
Some patterns, usually nested quantifiers like (a+)+, make a backtracking engine try an exponential number of paths on input that almost matches. The tester stops any run after 300ms, so a bad pattern can't freeze your tab. In production, that same pattern can take down a server (a ReDoS attack).
06

Sources

Formats were checked on 8 November 2026. Rules change; the official issuer wins if it disagrees.

07

More dev formats patterns

08

More from the workbench

Fine print

Tools: on the house.
Engineer: by the hour.

The regex was free. Code that doesn't need one is the upgrade: typed schemas, validated once at the edge, trusted everywhere after.

I'm Himanshu, an AI and full-stack engineer. I build MVPs, AI agents and the growth plumbing around them for early-stage startups.