UUID Regex Java Validator
Search...
⌘K
UUID Regex Java Validator
Search...
⌘K


UUID Regex Java Validator
Validate UUIDs in Java with ease using the UUID Regex Java Validator. Whether you’re working with databases, distributed systems, or backend services, this tool ensures your UUIDs follow correct formatting rules for reliable identification. Powered by Java’s java.util.regex, it’s ideal for testing patterns across APIs, logs, and data pipelines.
Looking to validate more fields in Java? Explore the:
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
What is a UUID?
A UUID (or GUID) is a 128-bit identifier used to uniquely label data. It appears as a 36-character string in this format:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
M: Indicates UUID version (1–5)
N: Indicates the variant (typically 8, 9, A, or B in hex)
UUIDs are essential for unique identification across APIs, distributed systems, databases, and resource tagging.
Java Regex Pattern for UUID
To match standard UUIDs (versions 1–5):
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
Pattern Breakdown:
[0-9a-fA-F]{8} – First group (8 hex digits)
[0-9a-fA-F]{4} – Second group (4 hex digits)
[1-5][0-9a-fA-F]{3} – Version (1–5)
[89abAB][0-9a-fA-F]{3} – Variant
[0-9a-fA-F]{12} – Final group (12 hex digits)
To strictly validate version 4 UUIDs:
"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}"
Java Implementation Example
To put this regex to work in Java, you can define it as a String
or compile it as a Pattern
for efficient reuse:
public static final String UUID_REGEX_STRING = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"; /** * Regular expression to match a standard UUID (versions 1–5), case-insensitive. */ public static final Pattern UUID_PATTERN = Pattern.compile(UUID_REGEX_STRING);
For validating specifically version 4 UUIDs, you might want to use a slightly stricter pattern:
public static final String UUID_V4_STRING = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}"; public static final Pattern UUID_V4 = Pattern.compile(UUID_V4_STRING);
These patterns ensure your UUID values are compliant with RFC 4122, catching common format mistakes before they hit your backend or database.
Version 4 UUID Pattern Breakdown
First group (8 hex digits)
Second group (4 hex digits)
Third group — the leading '4' specifically identifies it as version 4
Fourth group (variant, must begin with 8, 9, a, or b)
Final group (12 hex digits)
Java Code Example
import java.util.regex.Pattern; import java.util.regex.Matcher; public class UUIDValidator { public static void main(String[] args) { String uuid = "550e8400-e29b-41d4-a716-446655440000"; String regex = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(uuid); if (matcher.matches()) { System.out.println("Valid UUID"); } else { System.out.println("Invalid UUID"); } } }
Or, for strictly Version 4 UUIDs, use and the compiled as shown above.
Reusable Java UUID Patterns
// Generic UUID (any version) public static final String UUID_STRING = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"; public static final Pattern UUID = Pattern.compile(UUID_STRING, Pattern.CASE_INSENSITIVE); // Version 4 UUID only public static final String UUID_V4_STRING = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}"; public static final Pattern UUID_V4 = Pattern.compile(UUID_V4_STRING, Pattern.CASE_INSENSITIVE);
Valid UUID Examples
123e4567-e89b-12d3-a456-426614174000
550e8400-e29b-41d4-a716-446655440000
Invalid UUID Examples
123e4567e89b12d3a456426614174000 (missing hyphens)
zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz (non-hex characters)
123e4567-e89b-62d3-a456-426614174000 (invalid version)
Common Use Cases
Database Keys – Use UUIDs as non-sequential primary keys
Microservices – Avoid key collisions in distributed systems
API Resources – Identify RESTful endpoints and resources
User IDs – Generate anonymous, secure user identifiers
Pro Tips
Prefer Version 4 UUIDs: Use UUID version 4 (randomly generated) for security and simplicity.
Validate Everywhere: Validate UUID format on both frontend and backend to prevent malformed input.
Normalize for Consistency: Normalize UUIDs by converting to lowercase before comparing or storing.
Be Specific When Needed: If you expect only certain versions (e.g., v4), refine the regex to match only those using the version-specific pattern above.
By leveraging these patterns—and understanding the subtle differences between general and version-specific UUID regex—you can ensure your Java applications handle identifier validation robustly and efficiently.
Related Tools to Combine With
Java Regex Tester – Modify and test UUID regex variations
Token Generator – Generate secure alphanumeric tokens
Base64 Encoder – Encode UUIDs for transmission
UUID Generator – Instantly create UUIDs for tests
Email Regex Java Validator – Validate email formats
Password Regex Java Validator – Test strong password patterns
Frequently asked questions
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
UUID Regex Java Validator
Search...
⌘K
UUID Regex Java Validator
Search...
⌘K


UUID Regex Java Validator
UUID Regex Java Validator
Validate UUIDs in Java with ease using the UUID Regex Java Validator. Whether you’re working with databases, distributed systems, or backend services, this tool ensures your UUIDs follow correct formatting rules for reliable identification. Powered by Java’s java.util.regex, it’s ideal for testing patterns across APIs, logs, and data pipelines.
Looking to validate more fields in Java? Explore the:
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
UUID Regex Java Validator - Documentation
What is a UUID?
A UUID (or GUID) is a 128-bit identifier used to uniquely label data. It appears as a 36-character string in this format:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
M: Indicates UUID version (1–5)
N: Indicates the variant (typically 8, 9, A, or B in hex)
UUIDs are essential for unique identification across APIs, distributed systems, databases, and resource tagging.
Java Regex Pattern for UUID
To match standard UUIDs (versions 1–5):
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
Pattern Breakdown:
[0-9a-fA-F]{8} – First group (8 hex digits)
[0-9a-fA-F]{4} – Second group (4 hex digits)
[1-5][0-9a-fA-F]{3} – Version (1–5)
[89abAB][0-9a-fA-F]{3} – Variant
[0-9a-fA-F]{12} – Final group (12 hex digits)
To strictly validate version 4 UUIDs:
"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}"
Java Implementation Example
To put this regex to work in Java, you can define it as a String
or compile it as a Pattern
for efficient reuse:
public static final String UUID_REGEX_STRING = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"; /** * Regular expression to match a standard UUID (versions 1–5), case-insensitive. */ public static final Pattern UUID_PATTERN = Pattern.compile(UUID_REGEX_STRING);
For validating specifically version 4 UUIDs, you might want to use a slightly stricter pattern:
public static final String UUID_V4_STRING = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}"; public static final Pattern UUID_V4 = Pattern.compile(UUID_V4_STRING);
These patterns ensure your UUID values are compliant with RFC 4122, catching common format mistakes before they hit your backend or database.
Version 4 UUID Pattern Breakdown
First group (8 hex digits)
Second group (4 hex digits)
Third group — the leading '4' specifically identifies it as version 4
Fourth group (variant, must begin with 8, 9, a, or b)
Final group (12 hex digits)
Java Code Example
import java.util.regex.Pattern; import java.util.regex.Matcher; public class UUIDValidator { public static void main(String[] args) { String uuid = "550e8400-e29b-41d4-a716-446655440000"; String regex = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(uuid); if (matcher.matches()) { System.out.println("Valid UUID"); } else { System.out.println("Invalid UUID"); } } }
Or, for strictly Version 4 UUIDs, use and the compiled as shown above.
Reusable Java UUID Patterns
// Generic UUID (any version) public static final String UUID_STRING = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"; public static final Pattern UUID = Pattern.compile(UUID_STRING, Pattern.CASE_INSENSITIVE); // Version 4 UUID only public static final String UUID_V4_STRING = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}"; public static final Pattern UUID_V4 = Pattern.compile(UUID_V4_STRING, Pattern.CASE_INSENSITIVE);
Valid UUID Examples
123e4567-e89b-12d3-a456-426614174000
550e8400-e29b-41d4-a716-446655440000
Invalid UUID Examples
123e4567e89b12d3a456426614174000 (missing hyphens)
zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz (non-hex characters)
123e4567-e89b-62d3-a456-426614174000 (invalid version)
Common Use Cases
Database Keys – Use UUIDs as non-sequential primary keys
Microservices – Avoid key collisions in distributed systems
API Resources – Identify RESTful endpoints and resources
User IDs – Generate anonymous, secure user identifiers
Pro Tips
Prefer Version 4 UUIDs: Use UUID version 4 (randomly generated) for security and simplicity.
Validate Everywhere: Validate UUID format on both frontend and backend to prevent malformed input.
Normalize for Consistency: Normalize UUIDs by converting to lowercase before comparing or storing.
Be Specific When Needed: If you expect only certain versions (e.g., v4), refine the regex to match only those using the version-specific pattern above.
By leveraging these patterns—and understanding the subtle differences between general and version-specific UUID regex—you can ensure your Java applications handle identifier validation robustly and efficiently.
Related Tools to Combine With
Java Regex Tester – Modify and test UUID regex variations
Token Generator – Generate secure alphanumeric tokens
Base64 Encoder – Encode UUIDs for transmission
UUID Generator – Instantly create UUIDs for tests
Email Regex Java Validator – Validate email formats
Password Regex Java Validator – Test strong password patterns
Frequently asked questions
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex