Go (RE2)

UUID (v1–v5) in GO

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

Try it in the GO tester →

Pattern

regexGO
[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)

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)
	input := `550e8400-e29b-41d4-a716-446655440000`
	for _, match := range re.FindAllString(input, -1) {
		fmt.Println(match)
	}
}

Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.

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)