UUID (v4) Regex Pattern
Validates a canonical hyphenated UUID v4/GUID string by checking the RFC 9562 version nibble (4) and variant nibble (8, 9, a, or b) in the correct positions.
Reviewed May 31, 2026. Privacy model: tool input is processed in your browser and is not uploaded to BytePane servers.
Live Regex Tester
Pattern Breakdown
Code Examples
JavaScript
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const test = "550e8400-e29b-41d4-a716-446655440000";
console.log(regex.test(test)); // true
// Extract matches
const matches = test.match(regex);
console.log(matches);Python
import re
pattern = r'^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
test = "550e8400-e29b-41d4-a716-446655440000"
match = re.search(pattern, test, re.IGNORECASE)
print(match) # Found!Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
fmt.Println(re.MatchString("550e8400-e29b-41d4-a716-446655440000")) // true
}Common Use Cases
Match Examples
| Input | Result |
|---|---|
| 550e8400-e29b-41d4-a716-446655440000 | Match |
| 550e8400-e29b-51d4-a716-446655440000 | No Match |
UUID v4 regex variants for RFC 9562, GUID braces, compact IDs, and extraction
The base pattern validates canonical hyphenated UUID v4 strings. It checks the fixed version nibble (4) and RFC/IETF variant nibble (8, 9, a, or b). Regex can confirm the shape, but it cannot prove uniqueness, randomness quality, or whether the identifier was generated by a secure source.
| Variant | Pattern | Use it when |
|---|---|---|
| Canonical UUID v4 | ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ | Use with the i flag for normal API payloads, database IDs, request IDs, and GUID fields stored in 8-4-4-4-12 format. |
| UUID v4 with optional braces | ^\{?[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\}?$ | Use for systems that may receive Windows or .NET-style GUIDs such as {550e8400-e29b-41d4-a716-446655440000}. |
| Compact UUID v4 without hyphens | ^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$ | Use only when your system deliberately stores compact 32-character UUIDs with no dashes. |
| Extract UUID v4 from text | \b[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b | Use without anchors when parsing logs, trace IDs, support tickets, or text that may contain more than one UUID. |
Edge cases to test
550e8400-e29b-41d4-a716-446655440000MatchThe third group starts with 4 and the fourth group starts with a valid variant nibble.
550e8400-e29b-51d4-a716-446655440000No matchThis is not version 4 because the version nibble is 5.
550e8400-e29b-41d4-c716-446655440000No matchThe variant nibble c is not valid for the RFC/IETF variant in this v4 pattern.
550E8400-E29B-41D4-A716-446655440000Match with i flagThe page pattern uses the i flag, so uppercase hex is accepted.
{550e8400-e29b-41d4-a716-446655440000}No match in base patternUse the optional-braces variant if your input includes surrounding braces.
550e8400e29b41d4a716446655440000No match in base patternUse the compact variant only when your data intentionally removes hyphens.
Source checks
RFC 9562 UUID specification: Defines UUID versions and variants, including UUIDv4 as random/pseudorandom UUIDs with fixed version and variant fields.
MDN Crypto.randomUUID(): Documents browser generation of v4 UUIDs using a cryptographically secure random number generator.
About the UUID (v4) Regex
Validates a canonical hyphenated UUID v4/GUID string by checking the RFC 9562 version nibble (4) and variant nibble (8, 9, a, or b) in the correct positions.
Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The uuid (v4) pattern is classified as <strong>intermediate</strong> difficulty in the <strong>security & auth</strong> category. It works in all major programming languages.
When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.
More Security & Auth Patterns
Need More Regex Patterns?
Browse our complete library of 100+ regex patterns with interactive testers.
Frequently Asked Questions
What is the UUID (v4) regex pattern?
Validates a canonical hyphenated UUID v4/GUID string by checking the RFC 9562 version nibble (4) and variant nibble (8, 9, a, or b) in the correct positions.
How do I use the UUID (v4) regex?
Use the pattern /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i in your code. In JavaScript: new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', 'i'). Test it above with your own input.
What does this UUID (v4) regex match?
This pattern matches: "550e8400-e29b-41d4-a716-446655440000". It does NOT match: "550e8400-e29b-51d4-a716-446655440000". ID validation, database records, API responses.
Is the UUID (v4) regex beginner-friendly?
This pattern is rated Intermediate. It uses some advanced features like character classes and quantifiers.
What languages support the UUID (v4) regex?
This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.
Can I modify the UUID (v4) regex for my use case?
Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.
What is the correct regex for UUID v4?
Use ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ with the i flag when you need a canonical hyphenated UUID v4 string. The 4 checks the UUID version and [89ab] checks the RFC/IETF variant nibble.
Does a UUID v4 regex prove that an ID is unique?
No. Regex validates only the text format and fixed version or variant positions. It cannot prove uniqueness, randomness quality, database existence, or whether the UUID was generated by a secure random source.
Should I generate UUID v4 values with regex?
No. Generate UUID v4 values with a proper UUID generator such as crypto.randomUUID() in modern browsers or a trusted server-side UUID library. Use regex only to validate or extract existing UUID strings.
Should UUID v4 be used as a secret token?
Do not treat a UUID format check as a security boundary. UUIDs are identifiers, not authentication secrets. For password reset links, API keys, or session secrets, use purpose-built cryptographic token generation and compare tokens server-side.
Related Tools
JWT Token Regex
Intermediate Security & Auth pattern
API Key Pattern Regex
Advanced Security & Auth pattern
AWS Access Key Regex
Intermediate Security & Auth pattern
Base64 Encoded String Regex
Beginner Security & Auth pattern
MD5 Hash Regex
Beginner Security & Auth pattern
SHA-256 Hash Regex
Beginner Security & Auth pattern