Token-by-token breakdown
| Token | Meaning | Example |
|---|---|---|
^ |
Anchor: asserts position at start of the string | Start of 'a1b2c3d4-5678-90ef-1234-567890abcdef' |
[0-9a-fA-F] |
Character class: matches any single hexadecimal digit (0-9, a-f, A-F) | 0, 9, a, f, A, F |
{8} |
Quantifier: exactly 8 occurrences of the preceding token (hex digit) | a1b2c3d4 |
- |
Literal hyphen character | The hyphen in 'a1b2c3d4-5678...' |
[0-9a-fA-F] |
Character class: matches any single hexadecimal digit (0-9, a-f, A-F) | 5, 6, 7, 8 |
{4} |
Quantifier: exactly 4 occurrences of the preceding token (hex digit) | 5678 |
- |
Literal hyphen character | The hyphen in '...-5678-90ef...' |
[0-9a-fA-F] |
Character class: matches any single hexadecimal digit (0-9, a-f, A-F) | 9, 0, e, f |
{4} |
Quantifier: exactly 4 occurrences of the preceding token (hex digit) | 90ef |
- |
Literal hyphen character | The hyphen in '...-90ef-1234...' |
[0-9a-fA-F] |
Character class: matches any single hexadecimal digit (0-9, a-f, A-F) | 1, 2, 3, 4 |
{4} |
Quantifier: exactly 4 occurrences of the preceding token (hex digit) | 1234 |
- |
Literal hyphen character | The hyphen in '...-1234-567890abcdef' |
[0-9a-fA-F] |
Character class: matches any single hexadecimal digit (0-9, a-f, A-F) | 5, 6, 7, 8, 9, 0, a, b, c, d, e, f |
{12} |
Quantifier: exactly 12 occurrences of the preceding token (hex digit) | 567890abcdef |
$ |
Anchor: asserts position at end of the string | End of 'a1b2c3d4-5678-90ef-1234-567890abcdef' |
Matches
550e8400-e29b-41d4-a716-446655440000A1B2C3D4-5678-90EF-1234-567890ABCDEF00000000-0000-0000-0000-000000000000ffffffff-ffff-ffff-ffff-ffffffffffff
Does not match
550e8400-e29b-41d4-a716-44665544000550e8400-e29b-41d4-a716-4466554400000550e8400-e29b41d4-a716-446655440000550e8400-e29b-41d4-a716-44665544000g550e8400-e29b-41d4-a716-446655440000-
Common pitfalls
- Forgetting the anchors (^ and $) may match UUIDs embedded in longer strings.
- Using [0-9a-f] without the A-F part misses uppercase hex digits.
- Using [0-9a-f]+ instead of [0-9a-f]{n} may match invalid lengths.
- Assuming this matches all UUID versions (it only matches version-agnostic hex format).
- Not accounting for case sensitivity if the input may contain mixed case.
Performance notes
This pattern is linear in complexity and poses no risk of catastrophic backtracking. Anchors ensure full-string matching, preventing partial matches. For large inputs, consider using the 'i' flag if case insensitivity is desired (e.g., /^[0-9a-f]{8}...$/i).