JavaScript / ECMAScript

UUID (v1–v5) in JS

Match RFC 4122 UUIDs (versions 1–5) in the standard 8-4-4-4-12 hex format.

Try it in the JS tester →

Pattern

regexJS
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}   (flags: gi)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", "gi");
const input = "550e8400-e29b-41d4-a716-446655440000";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

The version nibble [1-5] and the variant bits [89ab] are constrained per RFC 4122. Matching is case-insensitive since UUIDs may be upper or lowercase.

Examples

Input

550e8400-e29b-41d4-a716-446655440000

Matches

  • 550e8400-e29b-41d4-a716-446655440000

Input

6ba7b810-9dad-11d1-80b4-00c04fd430c8

Matches

  • 6ba7b810-9dad-11d1-80b4-00c04fd430c8

Same pattern, other engines

← Back to UUID (v1–v5) overview (all engines)