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:


deadbeef-7331-4123-8123-ba5eba11babe
Possible security issues
This regex appears to be safe.
Explanation
  • [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 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");
        }
    }
}


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

  • Use version 4 UUIDs for better randomness

  • Always validate UUIDs on both frontend and backend

  • Normalize UUIDs by storing them in lowercase

  • Store UUIDs as VARCHAR(36) in SQL to retain format

  • Regex only checks format—use libraries for actual UUID generation


Related Tools to Combine With

Frequently asked questions

Does this regex validate all UUID versions?×
It matches versions 1 to 5. For more precise control, modify the pattern to match a specific version only.
Are UUIDs case-sensitive?+
Can this be used for database keys?+
What happens if the UUID is missing hyphens?+
How do I generate a UUID in Java?+
Can I import Figma designs?+
Is it SEO-friendly?+
Can I collaborate with my team?+
Is hosting included?+
Can I export code?+
Is there a free plan?+
Can I use custom fonts?+

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:


deadbeef-7331-4123-8123-ba5eba11babe
Possible security issues
This regex appears to be safe.
Explanation
  • [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 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");
        }
    }
}


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

  • Use version 4 UUIDs for better randomness

  • Always validate UUIDs on both frontend and backend

  • Normalize UUIDs by storing them in lowercase

  • Store UUIDs as VARCHAR(36) in SQL to retain format

  • Regex only checks format—use libraries for actual UUID generation


Related Tools to Combine With

Frequently asked questions

Does this regex validate all UUID versions?×
It matches versions 1 to 5. For more precise control, modify the pattern to match a specific version only.
Are UUIDs case-sensitive?+
Can this be used for database keys?+
What happens if the UUID is missing hyphens?+
How do I generate a UUID in Java?+