UUID Regex Go Validator

Search...

⌘K

UUID Regex Go Validator

Search...

⌘K


UUID Regex Go Validator

Validate UUIDs instantly with the UUID Regex Go Validator from Qodex. Whether you’re assigning user IDs or referencing resources, this tool ensures UUIDs are in the correct format. You can pair it with our API Key Generator, Username Generator, or Address Generator to build full mock datasets for testing and development.

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
Test your APIs today!

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

Regular Expression - Documentation

What is UUID Regex?


In Go, validating strings that must follow a UUID (Universally Unique Identifier) format is common in backend systems, APIs, and database records. UUIDs ensure that every entry has a globally unique ID—especially important when systems scale or operate across multiple servers.


UUIDs are typically formatted like this:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
  • x: Any hexadecimal digit

  • M: UUID version (1–5)

  • N: Variant (8, 9, a, or b)


A regex for validating UUIDs helps ensure that:

  • The input is the right length

  • The segments are correctly formatted

  • The UUID version and variant are valid


UUID Version 7 Regex Pattern


If you need to specifically match UUID version 7 (introduced for time-ordered identifiers), you can use this regex pattern in Go (and most programming languages that support standard regex syntax):


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


This pattern checks for:


  • 8 hex digits

  • 4 hex digits

  • A version digit (1–5)

  • A variant digit (8, 9, a, b)

  • 12 final hex digits


Here’s what’s different:

  • The third UUID segment must start with a to specify version 7.

  • The rest of the segments retain the hexadecimal and variant rules.

This ensures that only UUIDs of version 7 (e.g., ) are considered valid by your validator. Use this pattern if your application is leveraging the latest UUID specifications for time-based or sort-friendly IDs.


What’s New in UUID Version 7?

UUID version 7 brings a fresh approach, focusing on time-based ordering for better performance in modern distributed systems. Unlike older UUID versions, version 7 uses the Unix Epoch timestamp—measured in milliseconds since January 1, 1970, UTC, and not counting leap seconds—to build its unique values. This means:

  • Time-Ordered Values: IDs are naturally sortable by creation time, which can significantly speed up database operations and event logs.

  • Better Entropy: Version 7 improves randomness and uniqueness over versions 1 and 6, reducing the risk of collisions.

  • Scalability: The time-based structure makes UUIDs more efficient for high-throughput, multi-server applications.

By combining precise timestamps with extra randomness, UUIDv7 provides a sleek solution for scalable, reliable ID generation in APIs and databases.


Anatomy of a UUID v7


Let’s break down the structure of a UUID version 7 string. Like other UUIDs, it’s made up of 36 characters in total—including hyphens as separators. Here’s how the format looks on the surface:

  • Each x is a hexadecimal digit (0–9, a–f, or A–F).

  • The third group always starts with a 7, denoting version 7.

  • The N position in the fourth group represents the variant, which for standard UUIDs is typically one of 8, 9, a, or b.

Segment Breakdown


A UUID v7 string consists of five groups separated by hyphens:

  1. 8 hex digits

  2. 4 hex digits

  3. 4 hex digits (starting with “7”)

  4. 4 hex digits (first digit in this group is 8, 9, a, or b)

  5. 12 hex digits


So, for example, a valid UUID v7 might look like:

With this structure, Go programs (and many other platforms) can safely distinguish UUID v7 values and, in turn, capture information about when the ID was generated (since UUID v7 is time-ordered).

A regex for validating UUIDs helps ensure that:


How to Validate UUIDs in Go


Here’s a working Go example:


package main

import (
    "fmt"
    "regexp"
)

func isValidUUID(uuid string) bool {
    uuidRegex := regexp.MustCompile(`^[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}$`)
    return uuidRegex.MatchString(uuid)
}

func main() {
    test := "3f2504e0-4f89-11d3-9a0c-0305e82c3301"
    fmt.Println("Is UUID valid?", isValidUUID(test))
}


Validating UUID v7 with Regex Across Languages


If you need to specifically validate UUID version 7—which is gaining popularity for time-ordered identifiers—you'll want to fine-tune your regex. UUID v7s start with a "7" in the version position, so your pattern needs to reflect that.

Here’s a breakdown for major programming languages:


Go / JavaScript / Python / Java:

[^0-9a-fA-F]{8}-[0-9a-fA-F]{4}-7[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$
  • : 8 hex digits

  • : 4 hex digits

  • : "7" for version 7

  • : valid variant

  • : 12 hex digits

This regex ensures the version is exactly 7 and matches the correct UUID format, so you can use it in Go’s , Python’s , JavaScript’s , or Java’s .

Example (Go):

You can use this pattern directly in your application to guarantee only UUID v7s pass validation.


UUID v7 Support in Different Programming Languages


Wondering how UUID v7 stacks up across various programming languages? Here's a quick look at the current landscape:

  • PHP: Native support for UUID v7 is emerging in newer versions and popular open source libraries, but older PHP installations may require third-party packages or custom implementations.

  • JavaScript (ECMAScript): The official UUID API is steadily evolving, but not all environments (especially older browsers) support v7 out of the box. You’ll likely need a modern polyfill or a library like uuid.

  • Python: If you're using widely adopted libraries such as uuid7 or the latest editions of the standard library, v7 support is becoming more common. Just remember to check your library’s version.

  • Golang: With the Go community’s focus on strong library support, v7 is included in some popular packages, but isn’t universal quite yet. Always check your dependencies.

  • Java: Java 8 and above see support through third-party packages; however, built-in support remains limited. For production use, a well-maintained library is your friend.

  • .NET: The latest releases add UUID v7 to the standard toolkit, but older projects may need an external NuGet package.

  • Rust: Bleeding-edge UUID crate versions introduce v7 support. If you're up-to-date, you’re probably already covered.

In general: If you’re working in a modern environment and using up-to-date libraries, you’re more likely to have robust UUID v7 support. When in doubt, check your library’s documentation before generating those cutting-edge identifiers.


How is the time-ordered value field in UUID v7 generated?

In UUID version 7, the time-ordered value is generated based on the Unix Epoch timestamp—specifically, it uses the number of milliseconds that have elapsed since midnight, January 1, 1970 (UTC), excluding leap seconds. This approach ensures that each generated UUID not only remains unique but is also chronologically sortable. As a result, UUID v7 is particularly well-suited for distributed systems where events need ordering or time-based tracking, combining global uniqueness with built-in temporal information.


Use Cases


  • Assigning IDs in distributed databases

  • Identifying API users or sessions

  • Ensuring uniqueness in system logs or tokens

  • Referencing files, messages, or records across systems


Pro Tips for UUID Validation


  • UUIDs can be uppercase or lowercase—this regex supports both.

  • Version 4 UUIDs are most common for random generation. You can customize the pattern to only match v4 by replacing [1-5] with 4.

  • Always validate UUIDs before storing them in the database to prevent garbage data.

  • Avoid using UUIDs for user-facing identifiers unless you format or mask them properly—they can be long and hard to read.

  • Use Go’s regexp.MustCompile() instead of Compile() for static patterns—it’s faster and cleaner for runtime.


Combine with These Tools


Create full mock data flows by combining this validator with:


Frequently asked questions

What’s the difference between UUID versions?×
Each version (1–5) is generated differently. For example, v1 uses time, v4 is random, and v5 is based on hashing.
Is UUID validation case-sensitive?+
Can UUIDs be generated without dashes?+
Why is regex used to validate UUIDs?+
Is UUID validation necessary?+

UUID Regex Go Validator

Search...

⌘K

UUID Regex Go Validator

Search...

⌘K


UUID Regex Go Validator

UUID Regex Go Validator

Validate UUIDs instantly with the UUID Regex Go Validator from Qodex. Whether you’re assigning user IDs or referencing resources, this tool ensures UUIDs are in the correct format. You can pair it with our API Key Generator, Username Generator, or Address Generator to build full mock datasets for testing and development.

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
Test your APIs today!

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

Regular Expression - Documentation

What is UUID Regex?


In Go, validating strings that must follow a UUID (Universally Unique Identifier) format is common in backend systems, APIs, and database records. UUIDs ensure that every entry has a globally unique ID—especially important when systems scale or operate across multiple servers.


UUIDs are typically formatted like this:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
  • x: Any hexadecimal digit

  • M: UUID version (1–5)

  • N: Variant (8, 9, a, or b)


A regex for validating UUIDs helps ensure that:

  • The input is the right length

  • The segments are correctly formatted

  • The UUID version and variant are valid


UUID Version 7 Regex Pattern


If you need to specifically match UUID version 7 (introduced for time-ordered identifiers), you can use this regex pattern in Go (and most programming languages that support standard regex syntax):


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


This pattern checks for:


  • 8 hex digits

  • 4 hex digits

  • A version digit (1–5)

  • A variant digit (8, 9, a, b)

  • 12 final hex digits


Here’s what’s different:

  • The third UUID segment must start with a to specify version 7.

  • The rest of the segments retain the hexadecimal and variant rules.

This ensures that only UUIDs of version 7 (e.g., ) are considered valid by your validator. Use this pattern if your application is leveraging the latest UUID specifications for time-based or sort-friendly IDs.


What’s New in UUID Version 7?

UUID version 7 brings a fresh approach, focusing on time-based ordering for better performance in modern distributed systems. Unlike older UUID versions, version 7 uses the Unix Epoch timestamp—measured in milliseconds since January 1, 1970, UTC, and not counting leap seconds—to build its unique values. This means:

  • Time-Ordered Values: IDs are naturally sortable by creation time, which can significantly speed up database operations and event logs.

  • Better Entropy: Version 7 improves randomness and uniqueness over versions 1 and 6, reducing the risk of collisions.

  • Scalability: The time-based structure makes UUIDs more efficient for high-throughput, multi-server applications.

By combining precise timestamps with extra randomness, UUIDv7 provides a sleek solution for scalable, reliable ID generation in APIs and databases.


Anatomy of a UUID v7


Let’s break down the structure of a UUID version 7 string. Like other UUIDs, it’s made up of 36 characters in total—including hyphens as separators. Here’s how the format looks on the surface:

  • Each x is a hexadecimal digit (0–9, a–f, or A–F).

  • The third group always starts with a 7, denoting version 7.

  • The N position in the fourth group represents the variant, which for standard UUIDs is typically one of 8, 9, a, or b.

Segment Breakdown


A UUID v7 string consists of five groups separated by hyphens:

  1. 8 hex digits

  2. 4 hex digits

  3. 4 hex digits (starting with “7”)

  4. 4 hex digits (first digit in this group is 8, 9, a, or b)

  5. 12 hex digits


So, for example, a valid UUID v7 might look like:

With this structure, Go programs (and many other platforms) can safely distinguish UUID v7 values and, in turn, capture information about when the ID was generated (since UUID v7 is time-ordered).

A regex for validating UUIDs helps ensure that:


How to Validate UUIDs in Go


Here’s a working Go example:


package main

import (
    "fmt"
    "regexp"
)

func isValidUUID(uuid string) bool {
    uuidRegex := regexp.MustCompile(`^[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}$`)
    return uuidRegex.MatchString(uuid)
}

func main() {
    test := "3f2504e0-4f89-11d3-9a0c-0305e82c3301"
    fmt.Println("Is UUID valid?", isValidUUID(test))
}


Validating UUID v7 with Regex Across Languages


If you need to specifically validate UUID version 7—which is gaining popularity for time-ordered identifiers—you'll want to fine-tune your regex. UUID v7s start with a "7" in the version position, so your pattern needs to reflect that.

Here’s a breakdown for major programming languages:


Go / JavaScript / Python / Java:

[^0-9a-fA-F]{8}-[0-9a-fA-F]{4}-7[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$
  • : 8 hex digits

  • : 4 hex digits

  • : "7" for version 7

  • : valid variant

  • : 12 hex digits

This regex ensures the version is exactly 7 and matches the correct UUID format, so you can use it in Go’s , Python’s , JavaScript’s , or Java’s .

Example (Go):

You can use this pattern directly in your application to guarantee only UUID v7s pass validation.


UUID v7 Support in Different Programming Languages


Wondering how UUID v7 stacks up across various programming languages? Here's a quick look at the current landscape:

  • PHP: Native support for UUID v7 is emerging in newer versions and popular open source libraries, but older PHP installations may require third-party packages or custom implementations.

  • JavaScript (ECMAScript): The official UUID API is steadily evolving, but not all environments (especially older browsers) support v7 out of the box. You’ll likely need a modern polyfill or a library like uuid.

  • Python: If you're using widely adopted libraries such as uuid7 or the latest editions of the standard library, v7 support is becoming more common. Just remember to check your library’s version.

  • Golang: With the Go community’s focus on strong library support, v7 is included in some popular packages, but isn’t universal quite yet. Always check your dependencies.

  • Java: Java 8 and above see support through third-party packages; however, built-in support remains limited. For production use, a well-maintained library is your friend.

  • .NET: The latest releases add UUID v7 to the standard toolkit, but older projects may need an external NuGet package.

  • Rust: Bleeding-edge UUID crate versions introduce v7 support. If you're up-to-date, you’re probably already covered.

In general: If you’re working in a modern environment and using up-to-date libraries, you’re more likely to have robust UUID v7 support. When in doubt, check your library’s documentation before generating those cutting-edge identifiers.


How is the time-ordered value field in UUID v7 generated?

In UUID version 7, the time-ordered value is generated based on the Unix Epoch timestamp—specifically, it uses the number of milliseconds that have elapsed since midnight, January 1, 1970 (UTC), excluding leap seconds. This approach ensures that each generated UUID not only remains unique but is also chronologically sortable. As a result, UUID v7 is particularly well-suited for distributed systems where events need ordering or time-based tracking, combining global uniqueness with built-in temporal information.


Use Cases


  • Assigning IDs in distributed databases

  • Identifying API users or sessions

  • Ensuring uniqueness in system logs or tokens

  • Referencing files, messages, or records across systems


Pro Tips for UUID Validation


  • UUIDs can be uppercase or lowercase—this regex supports both.

  • Version 4 UUIDs are most common for random generation. You can customize the pattern to only match v4 by replacing [1-5] with 4.

  • Always validate UUIDs before storing them in the database to prevent garbage data.

  • Avoid using UUIDs for user-facing identifiers unless you format or mask them properly—they can be long and hard to read.

  • Use Go’s regexp.MustCompile() instead of Compile() for static patterns—it’s faster and cleaner for runtime.


Combine with These Tools


Create full mock data flows by combining this validator with:


Frequently asked questions

What’s the difference between UUID versions?×
Each version (1–5) is generated differently. For example, v1 uses time, v4 is random, and v5 is based on hashing.
Is UUID validation case-sensitive?+
Can UUIDs be generated without dashes?+
Why is regex used to validate UUIDs?+
Is UUID validation necessary?+