Advertisement

Pattern library / Numbers & Codes

Regex to Match UUID Version 4

Stricter than the generic UUID regex: enforces the version nibble 4 and the variant nibble 8/9/a/b that define UUID v4.

The pattern
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-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-446655440000Matchvalid v4 UUIDTry →
123e4567-e89b-12d3-a456-426614174000No matchversion 1, not 4Try →
550e8400-e29b-41d4-c716-446655440000No matchvariant c invalidTry →
not-a-uuidNo matchnot a UUIDTry →

Where to use it

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;
re.test('550e8400-e29b-41d4-a716-446655440000');  // true

Python

import re
re.match(r'^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', uuid, re.I)

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

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.