UUID / GUID Validation Regex
• CronOS Team
regexuuidguidvalidationtutorial
Need to generate a regex pattern?
Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!
UUID / GUID Validation Regex
Validate UUID (Universally Unique Identifier) or GUID (Globally Unique Identifier) in standard 8-4-4-4-12 hexadecimal format.
Pattern Breakdown
regex
^[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}$
Components
| Component | Description | Matches |
|---|---|---|
^ | Start anchor | Ensures match from string start |
[0-9a-fA-F]{8} | First group | Exactly 8 hex digits |
- | Separator | Literal hyphen |
[0-9a-fA-F]{4} | Second group | Exactly 4 hex digits |
- | Separator | Literal hyphen |
[0-9a-fA-F]{4} | Third group | Exactly 4 hex digits |
- | Separator | Literal hyphen |
[0-9a-fA-F]{4} | Fourth group | Exactly 4 hex digits |
- | Separator | Literal hyphen |
[0-9a-fA-F]{12} | Fifth group | Exactly 12 hex digits |
$ | End anchor | Ensures match to string end |
Character Classes
[0-9a-fA-F]- Hexadecimal digits: 0-9, a-f, A-F{8}- Quantifier: exactly 8 occurrences{4}- Quantifier: exactly 4 occurrences{12}- Quantifier: exactly 12 occurrences
Examples
Valid:
550e8400-e29b-41d4-a716-446655440000550E8400-E29B-41D4-A716-446655440000(uppercase)550e8400-e29b-41d4-a716-44665544000000000000-0000-0000-0000-000000000000
Invalid:
550e8400e29b41d4a716446655440000(missing hyphens)550e8400-e29b-41d4-a716-44665544000(missing digit)550e8400-e29b-41d4-a716-4466554400000(extra digit)550g8400-e29b-41d4-a716-446655440000(invalid hex character)550e8400-e29b-41d4-a716(incomplete)
Implementation
JavaScript
javascript
const uuidRegex = /^[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}$/;
uuidRegex.test('550e8400-e29b-41d4-a716-446655440000'); // true
uuidRegex.test('550E8400-E29B-41D4-A716-446655440000'); // true
uuidRegex.test('550e8400e29b41d4a716446655440000'); // false (missing hyphens)
Python
python
import re
uuid_regex = 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}$'
bool(re.match(uuid_regex, '550e8400-e29b-41d4-a716-446655440000')) # True
bool(re.match(uuid_regex, '550e8400e29b41d4a716446655440000')) # False
Go
go
uuidRegex := regexp.MustCompile(`^[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}$`)
uuidRegex.MatchString("550e8400-e29b-41d4-a716-446655440000") // true
uuidRegex.MatchString("550e8400e29b41d4a716446655440000") // false
Limitations
- Format only: Validates format, not actual UUID uniqueness
- No version validation: Doesn't validate UUID version (1-5) or variant
- Fixed format: Only validates standard format with hyphens
- No nil UUID check: Accepts all-zeros UUID
When to Use
- UUID format validation
- Database ID validation
- API parameter validation
- When you need to verify UUID structure
- Unique identifier input forms
For production, consider:
- Supporting UUIDs without hyphens if needed
- Validating UUID version and variant
- Using UUID parsing libraries
- Generating UUIDs with proper libraries
- Normalizing to lowercase or uppercase
Need to generate a regex pattern?
Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!