Pattern library / Validation
UUID Regex (8-4-4-4-12)
A UUID is four hex groups in the layout 8-4-4-4-12. Most systems never care which version (v1–v5) an ID is, so this pattern validates the layout — case-insensitively — without the over-fitted version-digit constraints that reject valid v4 alternates.
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
Load this pattern into the tester →
How the pattern works
- Group sizes are strict: 8, 4, 4, 4, 12 hex digits separated by hyphens.
[0-9a-fA-F]accepts both cases; lowercase the input first if you deduplicate IDs.- Strict v4 regexes force position 13 =
4and variant[89ab]— good for a specific generator, brittle as a general validator. - For
urn:uuid:prefixed forms, drop the anchors or add(urn:uuid:)?in front.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
550e8400-e29b-41d4-a716-446655440000 | Match | classic v4 layout | Try → |
550E8400-E29B-41D4-A716-446655440000 | Match | uppercase hex | Try → |
550e8400e29b41d4a716446655440000 | No match | hyphens required | Try → |
550e8400-e29b-41d4-a716-44665544000 | No match | last group 11 digits | Try → |
urn:uuid:550e8400-e29b-41d4-a716-446655440000 | No match | prefix (remove anchors to find) | Try → |
550g8400-e29b-41d4-a716-446655440000 | No match | g is not hex | Try → |
Where to use it
JavaScript
const UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
UUID.test('550e8400-e29b-41d4-a716-446655440000'); // true
Python
import re, uuid
s = '550e8400-e29b-41d4-a716-446655440000'
bool(re.fullmatch(r'[0-9a-fA-F-]{36}', s)) and s.count('-') == 4 # or try: uuid.UUID(s)
SQL / BigQuery
WHERE REGEXP_CONTAINS(id, r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')
Common mistakes
- 32-hex-no-hyphen IDs (Mongo ObjectId style, 24 chars) are not UUIDs — a different pattern.
- If your UUIDs are always lowercase, restrict to [0-9a-f] — marginally faster and stricter.
- Extracting a UUID from mixed text? Remove ^ and $ (the anchored form fails on prefixes, as the examples show).
FAQ
How do I validate a v4 UUID specifically?
Constrain the version digit and variant: ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$. The pattern on this page validates any version's layout.
Why does my UUID not match?
Check for whitespace, a urn:uuid: prefix, or a truncated group — the most common failures. Paste it into the tester to see the failing segment.
Is this pattern RE2 compatible?
Yes — pure character classes and literals, no lookaround or backreferences, so it runs in GA4, BigQuery, Go and Rust unchanged.
Related patterns
Hex Color Regex — Match #RGB & #RRGGBB · SemVer Regex — Match Semantic Versioning (2.0.0) · Extract Numbers from String — Regex + Examples
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.