REGEXVAULTv2.0
Web & Network/Misc
Verified Safe

UUID v4 Regex for Go

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

What this pattern does

This page provides a well-structured, multi-part regular expression for matching uuid v4, ported and verified for Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// UUID v4
// ReDoS-safe | RegexVault — Web & Network > Misc

package validation

import "regexp"

var uuidV4Re = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)

func ValidateUuidV4(s string) bool {
    return uuidV4Re.MatchString(s)
}

// Example
// fmt.Println(ValidateUuidV4("550e8400-e29b-41d4-a716-446655440000")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
550e8400-e29b-41d4-a716-446655440000550e8400-e29b-31d4-a716-446655440000
f47ac10b-58cc-4372-a567-0e02b2c3d479550e8400e29b41d4a716446655440000
6ba7b810-9dad-41d4-80b4-00c04fd430c8550e8400-e29b-41d4-c716-446655440000
110e8400-e29b-4fd4-b716-446655441111not-a-uuid
aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa550e8400-e29b-41d4-a716-44665544000g

When to use this pattern

This pattern is drawn from the Web & Network > Misc category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

UUID v4 does not guarantee global uniqueness — collision probability is negligible (1/2^122) but not zero. For high-security identifiers, use a CSPRNG and verify collision before storage.

Technical Notes

The 4 in position 13 (version) and the [89ab] in position 17 (variant) are the defining characteristics of UUID v4. The i flag allows uppercase hex.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern