The GUID Regex Java Validator helps developers confirm whether a GUID (Globally Unique Identifier) matches the correct syntax using Java regex. This is particularly useful for systems where unique object IDs, session tokens, or API keys are involved.
Explore related Java tools for data validation and encoding:
[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 GUID in Java?
A GUID (or UUID) is a 128-bit number used to uniquely identify data in systems. It is typically formatted as:
Where:
x is a hexadecimal digit
M indicates the version
N indicates the variant
A GUID helps ensure global uniqueness in distributed systems, databases, or API transactions.
Java Regex Pattern for GUID
The commonly used regex pattern for validating GUIDs:
What it matches:
8 hexadecimal digits
A hyphen
4 hexadecimal digits
A hyphen
4 hexadecimal digits starting with version 1–5
A hyphen
4 hexadecimal digits starting with 8, 9, A, or B (variant)
A hyphen
12 hexadecimal digits
Java Code Example
Sample Inputs
Valid GUIDs:
3f2504e0-4f89-11d3-9a0c-0305e82c3301
123e4567-e89b-12d3-a456-426614174000
550e8400-e29b-41d4-a716-446655440000
Invalid GUIDs:
3f2504e0-4f89-11d3-9a0c0305e82c3301 (missing hyphen)
zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz (non-hex characters)
12345 (too short)
Pro Tips
Always validate GUIDs before storing or using them in APIs or sessions.
GUIDs are case-insensitive. Your regex should allow both uppercase and lowercase letters (use a-fA-F).
Remove whitespace or invisible characters before running regex checks.
If you’re generating GUIDs in Java, use UUID.randomUUID().toString() for guaranteed format compliance.
For stricter validation, create version-specific patterns (e.g., only v4 UUIDs).
Never expose internal or sensitive GUIDs directly — hash or encode them with Hash Generator Java or Base64 Encoder.
Use Cases
API Key Validation: Ensure passed tokens follow GUID structure.
Database Keys: Confirm format of primary or foreign keys.
Logging Systems: Clean and validate UUID-based log identifiers.
Form Submissions: Accept only properly formatted GUIDs in front-end fields.
Combine with These Tools
UUID Regex Java Validator: Verify general UUIDs with version-specific matching.
Java Regex Tester: Tweak and test regex variations for different formats.
Token Generator: Generate unique tokens that mimic GUID formats.
Base64 Encoder: Encode validated GUIDs for secure transmission or storage.