UUID v1 Regex for Java
/^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iWhat this pattern does
This page provides a well-structured, multi-part regular expression for matching uuid v1, 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
// UUID v1
// ReDoS-safe | RegexVault — Web & Network > Misc
import java.util.regex.Pattern;
public class UuidV1Validator {
private static final Pattern PATTERN =
Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-1[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("a8098c1a-f86e-11da-bd1a-00112444be1e")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
a8098c1a-f86e-11da-bd1a-00112444be1e | a8098c1a-f86e-21da-bd1a-00112444be1e |
6ba7b810-9dad-11d1-80b4-00c04fd430c8 | a8098c1a-f86e-11da-c01a-00112444be1e |
00000000-0000-1000-8000-000000000000 | not-a-uuid |
ffffffff-ffff-1fff-bfff-ffffffffffff | a8098c1af86e11dabd1a00112444be1e |
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
The time component in UUID v1 encodes a 60-bit timestamp with 100-nanosecond precision — it can be decoded to determine when and potentially where an ID was generated.
Technical Notes
UUID v1 embeds the MAC address of the generating machine in the node field (last 12 hex chars) — a privacy concern. UUID v4 is preferred for security-sensitive identifiers.
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