JavaScript-compatible regex reference

UUID v4 Regex Pattern & Tester

Validate UUID version 4 strings with a pattern that checks the 8-4-4-4-12 hexadecimal layout, the version-4 nibble, and the RFC variant nibble. Use the live examples below before copying the pattern into JavaScript or another compatible regex engine.

Pattern

^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$

Flags: i

Live test vectors

Test the UUID v4 regex

Enter one value per line. Each line is tested against the whole-string pattern using the browser JavaScript RegExp engine.

PASS550e8400-e29b-41d4-a716-446655440000
PASS6ba7b810-9dad-4d1d-80b4-00c04fd430c8
PASSA987FBC9-4BED-4078-8F07-9141BA07C9F3
FAIL550e8400-e29b-11d4-a716-446655440000
FAIL550e8400-e29b-41d4-7716-446655440000
FAIL550e8400e29b41d4a716446655440000

Quick answer

For UUID v4, use a whole-string pattern that fixes the third group to version 4 and restricts the first character of the fourth group to 8, 9, a, or b. A generic UUID-shape regex is not enough when the version matters.

Common use cases

  • API request validation
  • Database identifier checks
  • Test-fixture verification

Pitfalls and limitations

  • !A generic 8-4-4-4-12 UUID pattern accepts versions other than v4.
  • !Case-insensitive matching is useful because hexadecimal UUID strings may use uppercase or lowercase letters.
  • !Regex verifies the textual structure; it does not prove that an identifier was generated randomly or is unique.

Known-valid examples

550e8400-e29b-41d4-a716-4466554400006ba7b810-9dad-4d1d-80b4-00c04fd430c8A987FBC9-4BED-4078-8F07-9141BA07C9F3

Known-invalid examples

550e8400-e29b-11d4-a716-446655440000550e8400-e29b-41d4-7716-446655440000550e8400e29b41d4a716446655440000

Continue testing and debugging

Frequently asked questions

What makes this pattern specific to UUID v4?

The first character of the third group is fixed to 4, which identifies version 4. The first character of the fourth group is restricted to 8, 9, a, or b for the standard variant.

Should UUID regex be case-sensitive?

Usually no. Hexadecimal UUID text is commonly written in lowercase, but uppercase A–F is also a normal representation, so this pattern uses the case-insensitive flag.

Does a regex prove a UUID is unique?

No. It only checks the string format and v4 markers. Uniqueness depends on how the UUID was generated and used.