Extraction

Regular expression

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

Pattern breakdown

PartMeaning
Anchor or contextUse anchors when you need whole-string validation.
Main tokenThe core token sequence describes the accepted text shape.
Character classCharacter classes limit which characters are valid.
QuantifierQuantifiers control how many characters or groups are accepted.
FlagsUse language-specific flags such as i, m, or u only when needed.

Should match

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

Should not match

  • not-a-uuid
  • not matching sample
  • 550e8400-e29b-41d4-a716-446655440000 invalid
  • not-a-uuid550e8400-e29b-41d4-a716-446655440000

Test cases

InputExpectedWhy it matters
550e8400-e29b-41d4-a716-446655440000MatchRepresentative valid input for this pattern.
not-a-uuidNo matchCommon invalid or boundary input.
(empty string)No matchCommon invalid or boundary input.
not matching sampleNo matchCommon invalid or boundary input.
550e8400-e29b-41d4-a716-446655440000 invalidNo matchCommon invalid or boundary input.
not-a-uuid550e8400-e29b-41d4-a716-446655440000No matchCommon invalid or boundary input.

JavaScript

const re = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
re.test(input);

Python

import re
bool(re.search(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", text))

PHP

$ok = preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $value) === 1;

Java

Pattern pattern = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$");
pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
ok := re.MatchString(value)

Notes and production use

UUID v4 regex is useful as a practical starting point. Test it against your real input, avoid using it as the only security control, and prefer a parser when the format has complex grammar.

Performance tip: avoid running complex regular expressions repeatedly on very large untrusted strings without limits. Prefer anchored validation patterns, cap input length before matching, and use a parser when the target format has nested grammar.