GUID Regex Javascript Validator
Search...
⌘K
GUID Regex Javascript Validator
Search...
⌘K


GUID Regex Javascript Validator
Easily validate GUIDs in JavaScript using our GUID Regex JavaScript Validator. Ensure every identifier matches the correct format of 8-4-4-4-12 hexadecimal characters—ideal for use in API development, form validation, and database management. Combine this tool with our JavaScript Regex Tester for pattern debugging or Email Validator for validating user credentials all in one place.
[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 a GUID (Globally Unique Identifier)?
A GUID is a 128-bit unique identifier commonly used in databases, software development, and APIs to ensure global uniqueness. It’s typically formatted as:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Each x is a hexadecimal character (0–9, a–f). For example: e4f50c60-4d42-11ec-81d3-0242ac130003.
JavaScript can use regular expressions (regex) to validate whether a given string matches this structure.
GUID Regex Pattern for JavaScript
Here is the regex pattern that matches a valid 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}$
Breakdown:
" ^ " : Anchor the pattern to the start and end of the string, ensuring the entire string matches the GUID format and nothing else sneaks in.
"[0-9a-fA-F]{8}" : First block – 8 hex characters, the first chunk of the GUID.
" - " : A literal hyphen separates each block.
" [0-9a-fA-F]{4} ": Second block – 4 hex characters, made up of 4 hex characters.
" - " : Another hyphen
" [1-5][0-9a-fA-F]{3} " : Third block – version field, starting with a digit from 1 to 5 to indicate the GUID version, followed by 3 more hex characters.
" - " : Another hyphen
" [89abAB][0-9a-fA-F]{3} " : Fourth block – variant field, starting with one of 8, 9, a, b (case-insensitive) for the variant, then 3 more hex chars.
" - " : Last hyphen before the final group.
" [0-9a-fA-F]{12} ": Final block – 12 hex characters, 2 hex characters wrap up the GUID.
Let’s break down what this regex is ensuring:
Anchors: The and at the beginning and end ensure the entire string is tested, not just a substring.
Hexadecimal Ranges: captures any digit or letter a–f (either case), perfectly matching the allowed GUID characters.
Dashes: The hyphens () are required at specific locations, dividing the GUID into its traditional 8-4-4-4-12 format.
Version Field: The ensures that the third block always starts with a version number between 1 and 5, as per GUID specs.
Variant Field: The at the start of the fourth block restricts the variant portion to accepted values.
Exact Length: No room for extra or missing characters—just the right number of hex digits and dashes.
This structure makes the pattern robust against common mistakes, like missing hyphens, extra characters, or invalid version/variant fields. It’s strict, concise, and ready for use in your JavaScript code!
This pattern ensures:
The string is the exact length and structure of a GUID.
Only valid hexadecimal characters are allowed.
The correct version and variant bits are present, which is crucial for GUID integrity.
The regex is case-insensitive for hexadecimal digits, but picky about placement of hyphens, version, and variant bits, making it robust for real-world validation.
Now, let's see how to put this regex to work in your JavaScript code.
Additional Regex Essentials
[abc]
: matches a single character ofa
,b
, orc
[^abc]
: matches any character excepta
,b
, orc
[a-zA-Z]
: matches any letter, uppercase or lowercase.
: matches any single characterab
: matches either'a'
or'b'
\s
: matches any whitespace character\S
: matches any non-whitespace character\d
: matches any digit\D
: matches any non-digit\w
: matches any word character (letters, digits, or underscore)\W
: matches any non-word character(?:...)
: non-capturing group(...)
: capturing groupa{3}
: exactly 3 of'a'
a{3,}
: 3 or more of'a'
a{3,6}
: between 3 and 6 of'a'
\b
: word boundary\B
: non-word boundary
Optional Braces in GUID Validation
Sometimes, you might encounter GUIDs wrapped with curly braces, like {3f2504e0-4f89-11d3-9a0c-0305e82c3301}
—a style that's common in some Microsoft environments and other software tools. If your application needs to accept GUIDs with or without these braces, you can update the regex pattern accordingly.
Here's how you can support both formats:
Use optional opening
{
and closing}
in your pattern.The adjusted regex looks like this:
^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$
Explanation:
^{
? Allows for an optional starting brace.[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}
matches the standard GUID structure.[}]?$
allows for an optional closing brace at the end.
This slight tweak makes your validation flexible, ensuring you catch both traditional and brace-wrapped GUIDs without false negatives.
How to Validate GUIDs in JavaScript
Here’s a complete working code snippet:
function isValidGUID(guid) { const guidRegex = /^[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 guidRegex.test(guid); } // Test example const testGUID = "a987fbc9-4bed-3078-cf07-9141ba07c9f3"; console.log(`Is "${testGUID}" valid?`, isValidGUID(testGUID));
How the Validation Works
Input the String: Pass the string you want to validate to the function.
Pattern Matching: The regex checks if the string matches the required GUID format.
Result: Returns if your string is a valid GUID, or otherwise.
This approach ensures your GUIDs are in the exact format expected, reducing the chance of subtle bugs sneaking into your system.
Handling Empty or Null Strings
Before running the regex validation, the function first checks if the input string is empty or null. If so, it immediately returns false
—ensuring that only non-empty values are considered for further validation. This prevents accidental acceptance of blank fields and helps keep your data clean right from the start.
Performance: Time and Space Complexity
Validating a GUID with this regular expression runs in linear time relative to the length of the input string—so, O(N), where N is the number of characters. The regex engine checks each character in the string exactly once while matching the pattern.
On the space front, validation uses a constant amount of extra memory—O(1)—since the regex itself and internal state don’t grow with input size. Whether you test a short string or a textbook-length UUID, your memory footprint remains minimal.
Examples
Valid GUID
3f2504e0-4f89-11d3-9a0c-0305e82c3301
Invalid GUIDs
3f2504e04f8911d39a0c0305e82c3301 (Missing hyphens)
3f25-04e0-4f89-11d3-9a0c (Too short)
ZZZ504e0-4f89-11d3-9a0c-0305e82c3301 (Invalid hex characters)
More Example Cases
To help clarify what a GUID is—and isn’t—here are some additional examples you might encounter when validating user input or API responses:
Valid formats:
3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Standard, no braces)
{3f2504e0-4f89-11d3-9a0c-0305e82c3301} (With curly braces)
3f2504e04f8911d39a0c0305e82c3301 (No hyphens, sometimes allowed in loose checks)
{3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)
Invalid formats:
3g2504e0-4f89-11d3-9a0c-0305e82c3301 (Non-hex character in first group)
3f2504e0-zz89-11d3-9a0c-0305e82c3301 (Non-hex character in second group)
3f2504e0-4f89-11d3z-9a0c-0305e82c3301 (Non-hex character in third group)
{3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Missing closing brace)
3f2504e0-4f89-11d3-9a0c-0305e82c3301} (Missing opening brace)
3f2504-4f89-11d3-9a0c-0305e82c3301 (Incorrect number of characters in first group)
3f2504e0-4f8-11d3-9a0c-0305e82c3301 (Incorrect number of characters in second group)
3f2504e0-4f89-113-9a0c-0305e82c3301 (Incorrect number of characters in third group)
3f2504e04f89-11d3-9a0c-0305e82c3301 (Incorrect grouping)
Edge cases:
{3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)
3f25-04e0-4f89-11d3-9a0c0305e82c3301 (Hyphens in wrong places)
{3f2504e0}-4f89-11d3-9a0c-0305e82c3301 (Mixed format with braces and misplaced hyphens)
When validating GUIDs, watch out not only for the length and hyphen placement but also for invalid characters (anything outside 0-9, a-f, or A-F) and mismatched or missing braces in wrapped formats. Checking these cases will help ensure your regex validation catches subtle mistakes that could otherwise slip through.
Interpreting the Match Information
When reviewing the match information, you'll notice each match is detailed with its position in the source text, the exact substring matched, and any captured groups. Here’s how to make sense of it all:
Match Span: This is shown as two numbers (e.g., 94–130), which mark the start and end index where the match occurs. Handy for troubleshooting or extracting data programmatically.
Matched String: This represents exactly what the regular expression found at that position—a quick way to see what was caught.
Understanding Captured Groups
Captured groups break down the inside of each match:
Group Number: Each group corresponds to a parenthetical section of your regex. Group 1 refers to the first set of parentheses, Group 2 to the second, and so on.
Group Span: Like the main match, each group’s span shows precisely where in the text the group began and ended. This lets you zero in on specific submatches.
Group Value: This column reveals what text the group actually matched. If you see “empty string,” that means the group didn’t capture anything for this particular match—perhaps because part of the pattern was optional.
In short, the match information gives you a map: you can see exactly what and where your pattern is identifying in your data, right down to the most granular grouping. This insight can be useful whether you’re debugging a regex, slicing apart complex data formats, or simply wanting a detailed account of what matches your pattern found.
Available Functions
Within this regex tool, you can do more than just find matches in your text. There’s support for:
Performing substitutions, so you can quickly replace patterns with your desired text
Listing all matches in one convenient view
Running unit tests to make sure your regular expressions perform as expected across different cases
Whether you’re checking for accuracy or automating text edits, these functions help streamline your workflow.
Performance Overview
When run against a sizable test string, this regular expression successfully identified 1,004 matches. The total time taken to execute was approximately 89.88 milliseconds, making it relatively efficient even with a large dataset.
Supported Regex Flavors
Regular expressions come in a variety of "flavors," each tailored to the quirks and needs of particular programming environments. Here are some of the most commonly supported types:
PCRE2 (used in modern PHP, version 7.3 and above)
PCRE (common in older PHP releases)
ECMAScript (the flavor used in JavaScript)
Python (as interpreted by Python's
re
library)Golang (Go's built-in regex engine)
Java 8 (Java’s regex capabilities as of version 8)
.NET 7.0 (used in C# and other .NET languages)
Rust (the regular expression crate for Rust projects)
Each flavor has its own syntax rules and supported features, so double-check compatibility when switching between languages and environments.
Uses of GUID Regex Validation
Database IDs: Ensure unique identifiers for database rows.
API Requests: Securely track request identifiers or session tokens.
Form Input Validation: Confirm GUID format for fields submitted via forms.
Distributed Systems: Uniquely identify resources across systems or services.
Pro Tips
Always convert GUIDs to lowercase or uppercase before validation if your app enforces a specific casing.
Consider client- and server-side validation to avoid tampering or malformed data entries.
If using random GUID generation, test it frequently using the GUID Validator to ensure format consistency.
Don’t confuse UUID v4 and GUID—they share formats but differ in generation logic.
How to Validate GUIDs in Python
If you’re working in Python and need to ensure your GUIDs (or UUIDs) are formatted correctly, you can leverage regular expressions for the task—just as we showed for JavaScript above. This approach is handy for validating user input, checking form fields, or handling API data.
Here’s a concise Python function to validate GUIDs using regex:
import re
def is_valid_guid(guid):
"""
Validates if the input string is a properly formatted GUID.
GUIDs can appear wrapped in curly braces (e.g., {xxxx-...-xxxx}).
"""
guid_pattern = re.compile(
r"^[{]?[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 bool(guid_pattern.match(guid))
Example Usage
test_guids = [
"3f2504e0-4f89-11d3-9a0c-0305e82c3301", # Valid
"{3f2504e0-4f89-11d3-9a0c-0305e82c3301}", # Valid (with braces)
"3f2504e0-4f89-11d3-9a0c-0305e82c3301-extra", # Invalid
"bad-guid-format", # Invalid
]
for guid in test_guids:
print(f"{guid}: {is_valid_guid(guid)}")
Tip: This pattern accepts optional curly braces—common in some database exports or API formats.
Note: If you need to support only certain GUID versions, tweak the regex’s
[1-5]
for the version field as needed.
Now you can confidently add Python to your toolbox for validating GUIDs in any data pipeline or backend workflow.
Validating GUIDs with a Java Regular Expression
If you’re working in Java and need to ensure a string matches the standard GUID format, regular expressions have you covered. Just like we saw in JavaScript, Java makes it easy to perform this validation in just a few lines of code.
Here’s how you can validate a GUID using Java's Pattern
and Matcher
classes:
import java.util.regex.Pattern;
public class GUIDValidator {
private static final Pattern GUID_PATTERN = Pattern.compile(
"^[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}$"
);
public static boolean isValidGUID(String guid) {
return guid != null && GUID_PATTERN.matcher(guid).matches();
}
}
Usage Example
Here's how you might use this validator in your application:
String guid = "3f2504e0-4f89-11d3-9a0c-0305e82c3301";
System.out.println("Is valid GUID? " + GUIDValidator.isValidGUID(guid));
// Output: Is valid GUID? True
This method will return true
if the provided string fits the standard format for a GUID—hyphens included and hexadecimal characters in the correct spots—and false
otherwise. Just pass any string you want to check, and you’ll know instantly whether it’s a valid GUID.
You can adapt this pattern for more permissive formats (like allowing curly braces or uppercase only) by tweaking the regex if needed, but the above code follows the canonical spec suitable for most APIs and databases.
How to Validate GUIDs in C#
If you're developing in C#, you can also check whether a string is a valid GUID using regular expressions. Here’s a practical, beginner-friendly approach for implementing GUID validation in C#:
Pattern details: The regex checks for either plain GUIDs (like
123e4567-e89b-12d3-a456-9AC7CBDCEE52
) or those wrapped in curly braces ({123e4567-e89b-12d3-a456-9AC7CBDCEE52}
).Validation logic: It matches groups of hexadecimal characters separated by hyphens, with optional braces at the start and end.
Here's a simple method to get you started:
using System.Text.RegularExpressions;
public static bool IsValidGuid(string input)
{
var guidPattern = @"^[{]?[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}[}]?$";
return Regex.IsMatch(input, guidPattern
Example usage:
Console.WriteLine(IsValidGuid("123e4567-e89b-12d3-a456-9AC7CBDCEE52")); // true
Console.WriteLine(IsValidGuid("{123e4567-e89b-12d3-a456-9AC7CBDCEE52}")); // true
Console.WriteLine(IsValidGuid("123e4567-h89b-12d3-a456")); // false
This small utility will quickly let you filter valid GUIDs from invalid ones, and it's handy for validating database keys, API tokens, or form inputs on the .NET stack.
Additional Helpful Tools
Code Generator: Instantly create JavaScript snippets for integrating your GUID regex into your projects.
Regex Debugger: Step through your regular expressions to spot errors and fine-tune your patterns.
Export Matches: Effortlessly export your regex match results for documentation or further analysis.
Benchmark Regex: Measure regex performance to ensure your validation remains efficient, even at scale.
With everything at your fingertips, validating GUIDs and related patterns has never been easier or more reliable.
Frequently asked questions
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
GUID Regex Javascript Validator
Search...
⌘K
GUID Regex Javascript Validator
Search...
⌘K


GUID Regex Javascript Validator
GUID Regex Javascript Validator
Easily validate GUIDs in JavaScript using our GUID Regex JavaScript Validator. Ensure every identifier matches the correct format of 8-4-4-4-12 hexadecimal characters—ideal for use in API development, form validation, and database management. Combine this tool with our JavaScript Regex Tester for pattern debugging or Email Validator for validating user credentials all in one place.
[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.
GUID Regex Javascript Validator - Documentation
What is a GUID (Globally Unique Identifier)?
A GUID is a 128-bit unique identifier commonly used in databases, software development, and APIs to ensure global uniqueness. It’s typically formatted as:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Each x is a hexadecimal character (0–9, a–f). For example: e4f50c60-4d42-11ec-81d3-0242ac130003.
JavaScript can use regular expressions (regex) to validate whether a given string matches this structure.
GUID Regex Pattern for JavaScript
Here is the regex pattern that matches a valid 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}$
Breakdown:
" ^ " : Anchor the pattern to the start and end of the string, ensuring the entire string matches the GUID format and nothing else sneaks in.
"[0-9a-fA-F]{8}" : First block – 8 hex characters, the first chunk of the GUID.
" - " : A literal hyphen separates each block.
" [0-9a-fA-F]{4} ": Second block – 4 hex characters, made up of 4 hex characters.
" - " : Another hyphen
" [1-5][0-9a-fA-F]{3} " : Third block – version field, starting with a digit from 1 to 5 to indicate the GUID version, followed by 3 more hex characters.
" - " : Another hyphen
" [89abAB][0-9a-fA-F]{3} " : Fourth block – variant field, starting with one of 8, 9, a, b (case-insensitive) for the variant, then 3 more hex chars.
" - " : Last hyphen before the final group.
" [0-9a-fA-F]{12} ": Final block – 12 hex characters, 2 hex characters wrap up the GUID.
Let’s break down what this regex is ensuring:
Anchors: The and at the beginning and end ensure the entire string is tested, not just a substring.
Hexadecimal Ranges: captures any digit or letter a–f (either case), perfectly matching the allowed GUID characters.
Dashes: The hyphens () are required at specific locations, dividing the GUID into its traditional 8-4-4-4-12 format.
Version Field: The ensures that the third block always starts with a version number between 1 and 5, as per GUID specs.
Variant Field: The at the start of the fourth block restricts the variant portion to accepted values.
Exact Length: No room for extra or missing characters—just the right number of hex digits and dashes.
This structure makes the pattern robust against common mistakes, like missing hyphens, extra characters, or invalid version/variant fields. It’s strict, concise, and ready for use in your JavaScript code!
This pattern ensures:
The string is the exact length and structure of a GUID.
Only valid hexadecimal characters are allowed.
The correct version and variant bits are present, which is crucial for GUID integrity.
The regex is case-insensitive for hexadecimal digits, but picky about placement of hyphens, version, and variant bits, making it robust for real-world validation.
Now, let's see how to put this regex to work in your JavaScript code.
Additional Regex Essentials
[abc]
: matches a single character ofa
,b
, orc
[^abc]
: matches any character excepta
,b
, orc
[a-zA-Z]
: matches any letter, uppercase or lowercase.
: matches any single characterab
: matches either'a'
or'b'
\s
: matches any whitespace character\S
: matches any non-whitespace character\d
: matches any digit\D
: matches any non-digit\w
: matches any word character (letters, digits, or underscore)\W
: matches any non-word character(?:...)
: non-capturing group(...)
: capturing groupa{3}
: exactly 3 of'a'
a{3,}
: 3 or more of'a'
a{3,6}
: between 3 and 6 of'a'
\b
: word boundary\B
: non-word boundary
Optional Braces in GUID Validation
Sometimes, you might encounter GUIDs wrapped with curly braces, like {3f2504e0-4f89-11d3-9a0c-0305e82c3301}
—a style that's common in some Microsoft environments and other software tools. If your application needs to accept GUIDs with or without these braces, you can update the regex pattern accordingly.
Here's how you can support both formats:
Use optional opening
{
and closing}
in your pattern.The adjusted regex looks like this:
^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$
Explanation:
^{
? Allows for an optional starting brace.[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}
matches the standard GUID structure.[}]?$
allows for an optional closing brace at the end.
This slight tweak makes your validation flexible, ensuring you catch both traditional and brace-wrapped GUIDs without false negatives.
How to Validate GUIDs in JavaScript
Here’s a complete working code snippet:
function isValidGUID(guid) { const guidRegex = /^[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 guidRegex.test(guid); } // Test example const testGUID = "a987fbc9-4bed-3078-cf07-9141ba07c9f3"; console.log(`Is "${testGUID}" valid?`, isValidGUID(testGUID));
How the Validation Works
Input the String: Pass the string you want to validate to the function.
Pattern Matching: The regex checks if the string matches the required GUID format.
Result: Returns if your string is a valid GUID, or otherwise.
This approach ensures your GUIDs are in the exact format expected, reducing the chance of subtle bugs sneaking into your system.
Handling Empty or Null Strings
Before running the regex validation, the function first checks if the input string is empty or null. If so, it immediately returns false
—ensuring that only non-empty values are considered for further validation. This prevents accidental acceptance of blank fields and helps keep your data clean right from the start.
Performance: Time and Space Complexity
Validating a GUID with this regular expression runs in linear time relative to the length of the input string—so, O(N), where N is the number of characters. The regex engine checks each character in the string exactly once while matching the pattern.
On the space front, validation uses a constant amount of extra memory—O(1)—since the regex itself and internal state don’t grow with input size. Whether you test a short string or a textbook-length UUID, your memory footprint remains minimal.
Examples
Valid GUID
3f2504e0-4f89-11d3-9a0c-0305e82c3301
Invalid GUIDs
3f2504e04f8911d39a0c0305e82c3301 (Missing hyphens)
3f25-04e0-4f89-11d3-9a0c (Too short)
ZZZ504e0-4f89-11d3-9a0c-0305e82c3301 (Invalid hex characters)
More Example Cases
To help clarify what a GUID is—and isn’t—here are some additional examples you might encounter when validating user input or API responses:
Valid formats:
3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Standard, no braces)
{3f2504e0-4f89-11d3-9a0c-0305e82c3301} (With curly braces)
3f2504e04f8911d39a0c0305e82c3301 (No hyphens, sometimes allowed in loose checks)
{3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)
Invalid formats:
3g2504e0-4f89-11d3-9a0c-0305e82c3301 (Non-hex character in first group)
3f2504e0-zz89-11d3-9a0c-0305e82c3301 (Non-hex character in second group)
3f2504e0-4f89-11d3z-9a0c-0305e82c3301 (Non-hex character in third group)
{3f2504e0-4f89-11d3-9a0c-0305e82c3301 (Missing closing brace)
3f2504e0-4f89-11d3-9a0c-0305e82c3301} (Missing opening brace)
3f2504-4f89-11d3-9a0c-0305e82c3301 (Incorrect number of characters in first group)
3f2504e0-4f8-11d3-9a0c-0305e82c3301 (Incorrect number of characters in second group)
3f2504e0-4f89-113-9a0c-0305e82c3301 (Incorrect number of characters in third group)
3f2504e04f89-11d3-9a0c-0305e82c3301 (Incorrect grouping)
Edge cases:
{3f2504e04f8911d39a0c0305e82c3301} (No hyphens, with braces)
3f25-04e0-4f89-11d3-9a0c0305e82c3301 (Hyphens in wrong places)
{3f2504e0}-4f89-11d3-9a0c-0305e82c3301 (Mixed format with braces and misplaced hyphens)
When validating GUIDs, watch out not only for the length and hyphen placement but also for invalid characters (anything outside 0-9, a-f, or A-F) and mismatched or missing braces in wrapped formats. Checking these cases will help ensure your regex validation catches subtle mistakes that could otherwise slip through.
Interpreting the Match Information
When reviewing the match information, you'll notice each match is detailed with its position in the source text, the exact substring matched, and any captured groups. Here’s how to make sense of it all:
Match Span: This is shown as two numbers (e.g., 94–130), which mark the start and end index where the match occurs. Handy for troubleshooting or extracting data programmatically.
Matched String: This represents exactly what the regular expression found at that position—a quick way to see what was caught.
Understanding Captured Groups
Captured groups break down the inside of each match:
Group Number: Each group corresponds to a parenthetical section of your regex. Group 1 refers to the first set of parentheses, Group 2 to the second, and so on.
Group Span: Like the main match, each group’s span shows precisely where in the text the group began and ended. This lets you zero in on specific submatches.
Group Value: This column reveals what text the group actually matched. If you see “empty string,” that means the group didn’t capture anything for this particular match—perhaps because part of the pattern was optional.
In short, the match information gives you a map: you can see exactly what and where your pattern is identifying in your data, right down to the most granular grouping. This insight can be useful whether you’re debugging a regex, slicing apart complex data formats, or simply wanting a detailed account of what matches your pattern found.
Available Functions
Within this regex tool, you can do more than just find matches in your text. There’s support for:
Performing substitutions, so you can quickly replace patterns with your desired text
Listing all matches in one convenient view
Running unit tests to make sure your regular expressions perform as expected across different cases
Whether you’re checking for accuracy or automating text edits, these functions help streamline your workflow.
Performance Overview
When run against a sizable test string, this regular expression successfully identified 1,004 matches. The total time taken to execute was approximately 89.88 milliseconds, making it relatively efficient even with a large dataset.
Supported Regex Flavors
Regular expressions come in a variety of "flavors," each tailored to the quirks and needs of particular programming environments. Here are some of the most commonly supported types:
PCRE2 (used in modern PHP, version 7.3 and above)
PCRE (common in older PHP releases)
ECMAScript (the flavor used in JavaScript)
Python (as interpreted by Python's
re
library)Golang (Go's built-in regex engine)
Java 8 (Java’s regex capabilities as of version 8)
.NET 7.0 (used in C# and other .NET languages)
Rust (the regular expression crate for Rust projects)
Each flavor has its own syntax rules and supported features, so double-check compatibility when switching between languages and environments.
Uses of GUID Regex Validation
Database IDs: Ensure unique identifiers for database rows.
API Requests: Securely track request identifiers or session tokens.
Form Input Validation: Confirm GUID format for fields submitted via forms.
Distributed Systems: Uniquely identify resources across systems or services.
Pro Tips
Always convert GUIDs to lowercase or uppercase before validation if your app enforces a specific casing.
Consider client- and server-side validation to avoid tampering or malformed data entries.
If using random GUID generation, test it frequently using the GUID Validator to ensure format consistency.
Don’t confuse UUID v4 and GUID—they share formats but differ in generation logic.
How to Validate GUIDs in Python
If you’re working in Python and need to ensure your GUIDs (or UUIDs) are formatted correctly, you can leverage regular expressions for the task—just as we showed for JavaScript above. This approach is handy for validating user input, checking form fields, or handling API data.
Here’s a concise Python function to validate GUIDs using regex:
import re
def is_valid_guid(guid):
"""
Validates if the input string is a properly formatted GUID.
GUIDs can appear wrapped in curly braces (e.g., {xxxx-...-xxxx}).
"""
guid_pattern = re.compile(
r"^[{]?[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 bool(guid_pattern.match(guid))
Example Usage
test_guids = [
"3f2504e0-4f89-11d3-9a0c-0305e82c3301", # Valid
"{3f2504e0-4f89-11d3-9a0c-0305e82c3301}", # Valid (with braces)
"3f2504e0-4f89-11d3-9a0c-0305e82c3301-extra", # Invalid
"bad-guid-format", # Invalid
]
for guid in test_guids:
print(f"{guid}: {is_valid_guid(guid)}")
Tip: This pattern accepts optional curly braces—common in some database exports or API formats.
Note: If you need to support only certain GUID versions, tweak the regex’s
[1-5]
for the version field as needed.
Now you can confidently add Python to your toolbox for validating GUIDs in any data pipeline or backend workflow.
Validating GUIDs with a Java Regular Expression
If you’re working in Java and need to ensure a string matches the standard GUID format, regular expressions have you covered. Just like we saw in JavaScript, Java makes it easy to perform this validation in just a few lines of code.
Here’s how you can validate a GUID using Java's Pattern
and Matcher
classes:
import java.util.regex.Pattern;
public class GUIDValidator {
private static final Pattern GUID_PATTERN = Pattern.compile(
"^[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}$"
);
public static boolean isValidGUID(String guid) {
return guid != null && GUID_PATTERN.matcher(guid).matches();
}
}
Usage Example
Here's how you might use this validator in your application:
String guid = "3f2504e0-4f89-11d3-9a0c-0305e82c3301";
System.out.println("Is valid GUID? " + GUIDValidator.isValidGUID(guid));
// Output: Is valid GUID? True
This method will return true
if the provided string fits the standard format for a GUID—hyphens included and hexadecimal characters in the correct spots—and false
otherwise. Just pass any string you want to check, and you’ll know instantly whether it’s a valid GUID.
You can adapt this pattern for more permissive formats (like allowing curly braces or uppercase only) by tweaking the regex if needed, but the above code follows the canonical spec suitable for most APIs and databases.
How to Validate GUIDs in C#
If you're developing in C#, you can also check whether a string is a valid GUID using regular expressions. Here’s a practical, beginner-friendly approach for implementing GUID validation in C#:
Pattern details: The regex checks for either plain GUIDs (like
123e4567-e89b-12d3-a456-9AC7CBDCEE52
) or those wrapped in curly braces ({123e4567-e89b-12d3-a456-9AC7CBDCEE52}
).Validation logic: It matches groups of hexadecimal characters separated by hyphens, with optional braces at the start and end.
Here's a simple method to get you started:
using System.Text.RegularExpressions;
public static bool IsValidGuid(string input)
{
var guidPattern = @"^[{]?[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}[}]?$";
return Regex.IsMatch(input, guidPattern
Example usage:
Console.WriteLine(IsValidGuid("123e4567-e89b-12d3-a456-9AC7CBDCEE52")); // true
Console.WriteLine(IsValidGuid("{123e4567-e89b-12d3-a456-9AC7CBDCEE52}")); // true
Console.WriteLine(IsValidGuid("123e4567-h89b-12d3-a456")); // false
This small utility will quickly let you filter valid GUIDs from invalid ones, and it's handy for validating database keys, API tokens, or form inputs on the .NET stack.
Additional Helpful Tools
Code Generator: Instantly create JavaScript snippets for integrating your GUID regex into your projects.
Regex Debugger: Step through your regular expressions to spot errors and fine-tune your patterns.
Export Matches: Effortlessly export your regex match results for documentation or further analysis.
Benchmark Regex: Measure regex performance to ensure your validation remains efficient, even at scale.
With everything at your fingertips, validating GUIDs and related patterns has never been easier or more reliable.
Frequently asked questions
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex
Discover, Test, and Secure your APIs — 10x Faster.

Product
All Rights Reserved.
Copyright © 2025 Qodex