Regex Patterns

UUID v4

Match UUID v4 identifiers with the standard 8-4-4-4-12 hex format and version check.

What Is This?

This regex pattern matches UUID v4 (random) identifiers. UUIDs are 36-character strings in the format 8-4-4-4-12 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). This pattern specifically validates v4 UUIDs by checking that the version digit is 4 and the variant digits start with 8, 9, A, or B.

How to Use

1

The Pattern

Use this pattern to validate UUID v4 inputs in forms and APIs. The pattern checks the correct UUID structure: 8 hex digits, hyphen, 4 hex digits, hyphen, '4' followed by 3 hex digits (version 4 check), hyphen, hex digits starting with 8/9/A/B (variant check), hyphen, 12 hex digits.

/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$/i

Examples

Example

Valid UUID v4

Matches:
550e8400-e29b-41d4-a716-446655440000
f47ac10b-58cc-4372-a567-0e02b2c3d479

Does not match:
550e8400-e29b-31d4-a716-446655440000
not-a-uuid
12345
Example

Invalid UUID formats

Matches:
c9bf9e57-1685-4c89-bafb-ff5af830be8a
9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d

Does not match:
c9bf9e57-1685-3c89-bafb-ff5af830be8a
c9bf9e57-1685-4c89-xafb-ff5af830be8a

Related Entries

More from this reference:

Frequently Asked Questions

What about other UUID versions?

Change the version digit check: v1 (1), v3 (3), v4 (4), v5 (5), v7 (7). For generic UUID validation (any version), use: ^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$.

Should I validate UUID format on the server?

Always validate UUID format server-side before using it in database queries to prevent injection attacks. PostgreSQL has a native uuid type that validates the format automatically.