Regex for UUID / GUID Identifier

RFC 4122 compliant regular expression verifying 128-bit hex blocks with version nibble (1-5) and variant bits (8, 9, a, or b).

/

⚡ Live Interactive Sandbox

Validation Result: MATCH ✓

Pattern Breakdown & Tokens

  • • ^[0-9a-fA-F]{8}- — initial 8-character hexadecimal chunk
  • • [0-9a-fA-F]{4}- — second 4-character hex chunk
  • • [1-5][0-9a-fA-F]{3}- — version digit (1 through 5) and 3 hex digits
  • • [89abAB][0-9a-fA-F]{3}- — RFC 4122 variant indicator and 3 hex digits
  • • [0-9a-fA-F]{12}$ — terminal 12-character node sequence

Code Snippets

JavaScript
const uuidRegex = /^[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}$/;
const isValid = uuidRegex.test(uuid);
Python
import re
pattern = r"^[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}$"
is_valid = bool(re.match(pattern, uuid))
Go (Golang)
matched, err := regexp.MatchString(`^[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}$`, uuid)
PHP
$isValid = preg_match('/^[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}$/', $uuid);

Open the full tool: Open Full Regex Tester →

FAQ

How does this regular expression for UUID / GUID Identifier work?

RFC 4122 compliant regular expression verifying 128-bit hex blocks with version nibble (1-5) and variant bits (8, 9, a, or b). The pattern is: ^[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}$

How to use this regex in JavaScript and Python?

In JavaScript: new RegExp("^[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}$").test(input). In Python: re.match(r"^[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}$", input).

Can I test complex regular expressions online?

Yes, use our full in-browser Regex Tester tool with live syntax highlighting, group capture table, and zero server uploads.

🔗 Share this page

TelegramWhatsAppX