REGEXVAULTv2.0
Web & Network/Misc
Verified Safe

UUID Any Version (v1–v8) Regex for Java

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][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 any version (v1–v8), ported and verified for Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

Java
// UUID Any Version (v1–v8)
// ReDoS-safe | RegexVault — Web & Network > Misc

import java.util.regex.Pattern;

public class UuidAnyVersionV1v8Validator {
    private static final Pattern PATTERN =
        Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("550e8400-e29b-41d4-a716-446655440000")); // true
    }
}

Test Cases

Matches (Valid)
Rejects (Invalid)
550e8400-e29b-41d4-a716-446655440000550e8400-e29b-91d4-a716-446655440000
a8098c1a-f86e-11da-bd1a-00112444be1e00000000-0000-0000-0000-000000000000
00000000-0000-8000-8000-000000000000not-a-uuid
ffffffff-ffff-5fff-9fff-ffffffffffff550e8400e29b41d4a716446655440000

When to use this pattern

This pattern is drawn from the Web & Network > Misc category and carries a ReDoS-safe certification. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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 version 0 (nil UUID: 00000000-0000-0000-0000-000000000000) is valid structurally but not as a versioned UUID. Validate separately if nil UUIDs are meaningful in your domain.

Technical Notes

Versions 6, 7, and 8 are defined in RFC 9562 (2024). Version 0 and 9+ are not valid. The nil UUID (all zeros) does not have a valid version number.

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