~/devtools / regex / uuid
tool::regex-guide

regex uuid

/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i

UUID / GUID Validation

ad · 728×90
Regex Pattern
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
Flags:i
Pattern Breakdown
^[0-9a-f]{8}8 hex digits (time_low)
-Hyphen separator
[0-9a-f]{4}4 hex digits (time_mid)
-Hyphen separator
[0-9a-f]{4}4 hex digits (time_hi_version)
-Hyphen separator
[0-9a-f]{4}4 hex digits (clock_seq)
-Hyphen separator
[0-9a-f]{12}$12 hex digits (node)
Matching Examples
✓550e8400-e29b-41d4-a716-446655440000
✓6ba7b810-9dad-11d1-80b4-00c04fd430c8
✓00000000-0000-0000-0000-000000000000
Non-Matching Examples
✗550e8400e29b41d4a716446655440000
✗550e8400-e29b-41d4-a716
✗gggggggg-gggg-gggg-gggg-gggggggggggg

Validates the standard 8-4-4-4-12 UUID format used in v1 through v5. Case-insensitive (flag i), accepting only hexadecimal characters in the correct hyphenated positions.

Language Usage

JavaScript— Use RegExp object or literal syntax
const pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

// Test a string
console.log(pattern.test("550e8400-e29b-41d4-a716-446655440000")); // true
console.log(pattern.test("550e8400e29b41d4a716446655440000")); // false

// Match and extract
const result = "550e8400-e29b-41d4-a716-446655440000".match(pattern);
Python— Use the re module
import re

pattern = r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
flags = re.IGNORECASE

# Test a string
if re.fullmatch(pattern, "550e8400-e29b-41d4-a716-446655440000", flags):
    print("Valid")

# Find all matches in text
matches = re.findall(pattern, text, flags)
Java— Use java.util.regex package
import java.util.regex.*;

String pattern = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher("550e8400-e29b-41d4-a716-446655440000");
boolean isValid = m.matches(); // true

// Find occurrences
Matcher finder = p.matcher(inputText);
while (finder.find()) {
    System.out.println(finder.group());
}

Common Use Cases

  • ▸Validate database primary key format
  • ▸Verify UUID parameters in API requests
  • ▸Validate unique identifiers in distributed systems
  • ▸Check UUID fields in JWT claims
  • ▸Extract UUID patterns from filenames

Related Patterns

email/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-…/i→phone/^\+?[\d\s\-\(\)]{7,15}$/→url/^https?:\/\/[^\s\/$.?#].[^\s]*$/i→ip-address/^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.…/→
ad · 300×250
← Back to Regex Tester
// related tools
⏱
Cron Expression Generator
Build and parse cron expressions visually. Generate human-readable descriptions and preview next execution times.
jwt
JWT Decoder
Decode and inspect JWT tokens. View header, payload, and signature details.
◑
Color Converter
Convert colors between HEX, RGB, HSL, and more. Pick colors visually.
ts
Timestamp Converter
Convert Unix timestamps to human-readable dates. Supports ms/s, UTC/local, and relative time.