GUID Regex Go Validator

Search...

⌘K

GUID Regex Go Validator

Search...

⌘K


GUID Regex Go Validator

GUID Regex Go Validator

Use the GUID Regex Go Validator to ensure your unique identifiers follow the correct structure. Test and debug your regex in the Go Regex Tester or validate associated data like emails, URLs, and passwords for a complete data quality workflow.

deadbeef-7331-4123-8123-ba5eba11babe
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

Introduction: What Is GUID Regex?

In Go (Golang), a GUID (Globally Unique Identifier), also known as a UUID (Universally Unique Identifier), is used to identify resources uniquely across distributed systems. It ensures that no two values are ever the same, making it vital for tracking, versioning, and referencing.


A GUID looks like this:

3f2504e0-4f89-11d3-9a0c-0305e82c3301


It contains 32 hexadecimal characters arranged into 5 groups separated by hyphens, following the pattern:


8-4-4-4-12


The most reliable way to validate GUID formats in Go is using regular expressions (regex). Regex allows you to match and verify this structure before storing or processing the data.


GUID Regex Pattern (with Breakdown)


Here’s the regex pattern we use to validate a GUID:


^[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}$


Explanation:


  • [0-9a-fA-F]{8} – First group of 8 hexadecimal digits

  • - – Hyphen separator

  • [0-9a-fA-F]{4} – Second group of 4 digits

  • [1-5][0-9a-fA-F]{3} – Version digit (1–5) + 3 more hex digits

  • [89abAB][0-9a-fA-F]{3} – Variant digit (starting with 8, 9, a, or b) + 3 hex digits

  • [0-9a-fA-F]{12} – Final 12 hex digits


How to Validate GUIDs in Go Using Regex


You can validate GUIDs using the regexp package in Go. Here’s the complete Go code:


package main

import (
    "fmt"
    "regexp"
)

func isValidGUID(guid string) bool {
    pattern := `^[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}$`
    regex := regexp.MustCompile(pattern)
    return regex.MatchString(guid)
}

func main() {
    samples := []string{
        "3f2504e0-4f89-11d3-9a0c-0305e82c3301", // valid
        "3F2504E0-4F89-11D3-9A0C-0305E82C3301", // valid uppercase
        "123e4567e89b12d3a456426614174000",     // invalid (no hyphens)
        "3f25-04e0-4f89-11d3-9a0c-0305e82c3301", // invalid (group mismatch)
    }

    for _, guid := range samples {
        fmt.Printf("GUID: %s | Valid: %t\n", guid, isValidGUID(guid))
    }
}


Real-World Use Cases


  • Database Primary Keys: Useful for identifying records in distributed databases.

  • API Resource Identifiers: RESTful services use GUIDs for resources like /user/3f2504e0-4f89-11d3-9a0c-0305e82c3301.

  • Session Tokens: Web apps often use UUIDs to track secure sessions.

  • Device or File IDs: Many cloud storage services use GUIDs to uniquely reference files.


Pro Tips


  • Always use lowercase or uppercase consistently when displaying GUIDs.

  • Regex validates the format only — not whether the GUID is truly unique.

  • Never expose GUIDs that relate to sensitive resources in unsecured URLs.

  • Use regex for validation but libraries like github.com/google/uuid for generation.

  • For batch testing, use the Go Regex Tester to try different formats quickly.


Combine with These Tools


Use the GUID Regex Go Validator alongside these tools to ensure your data pipeline is complete:


Frequently asked questions

What’s the difference between GUID and UUID?×
GUID and UUID are functionally the same — GUID is used in Microsoft ecosystems, while UUID is the formal RFC term.
Can this regex detect fake or duplicate GUIDs?+
Does this regex validate all versions of UUIDs?+
Are uppercase letters in GUIDs valid?+
Can I remove hyphens from the regex?+