Advertisement

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.

The pattern
^[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

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
550e8400-e29b-41d4-a716-446655440000Matchclassic v4 layoutTry →
550E8400-E29B-41D4-A716-446655440000Matchuppercase hexTry →
550e8400e29b41d4a716446655440000No matchhyphens requiredTry →
550e8400-e29b-41d4-a716-44665544000No matchlast group 11 digitsTry →
urn:uuid:550e8400-e29b-41d4-a716-446655440000No matchprefix (remove anchors to find)Try →
550g8400-e29b-41d4-a716-446655440000No matchg is not hexTry →

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

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

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.

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.