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
-4[0-9a-f]{3}-— version nibble is 4.-[89ab][0-9a-f]{3}-— variant nibble is 8/9/a/b.- Case-insensitive: add the
iflag if uppercase UUIDs occur.
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 | valid v4 UUID | Try → |
123e4567-e89b-12d3-a456-426614174000 | No match | version 1, not 4 | Try → |
550e8400-e29b-41d4-c716-446655440000 | No match | variant c invalid | Try → |
not-a-uuid | No match | not a UUID | Try → |
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.
FAQ
Related patterns
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.