Mac Address Regex Go Validator

Search...

⌘K

Mac Address Regex Go Validator

Search...

⌘K


Mac Address Regex Go Validator

Mac Address Regex Go Validator

Need to validate MAC addresses in Go? The Qodex MAC Address Regex Go Validator helps ensure your patterns match standard formats like 01:23:45:67:89:AB. Ideal for networking, device authentication, and input validation.


Pair it with the IP Regex Go Validator, UUID Generator, or API Key Generator for secure test setups. Add Username, Email, or Phone Number Generators to complete mock profiles with ease.

bb:aa:dd:aa:55:55
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
Match 1: "bb:aa:dd:aa:55:55" at index 0
Test your APIs today!

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

Regular Expression - Documentation

MAC Address Regex Go Validator


A MAC address (Media Access Control address) is a unique identifier used to label devices on a network. Validating these addresses is critical in systems that track, authorize, or communicate with hardware components. The Qodex MAC Address Regex Go Validator helps developers and testers quickly confirm whether a string follows valid MAC formatting using Go’s regexp package.


What is a MAC Address Regex?


In Go, you can use regular expressions to match MAC address patterns. A typical MAC address looks like this:


01:23:45:67:89:AB  
or  
01-23-45-67-89-AB


MAC addresses are composed of six groups of two hexadecimal digits separated by either colons or hyphens. The regex must ensure this format without allowing extra characters or missing segments.


Regex Pattern for MAC Addresses


Here’s the recommended Go regex for matching standard MAC addresses:


^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$


What it means:

  • ^ – Start of string

  • ([0-9a-fA-F]{2}[:-]){5} – Five pairs of hex digits followed by : or -

  • [0-9a-fA-F]{2} – Final pair without a separator

  • $ – End of string


This ensures the string is exactly 6 pairs and uses consistent separators.


How It Works


  1. Input or paste your regex (or use the default).

  2. Enter a test MAC address.

  3. Instantly see whether it matches or fails.

  4. Adjust your pattern as needed and validate again.


Example: Basic Validator


Use the Go Regex Tester to experiment with variations.


package main

import (
    "fmt"
    "regexp"
)

func isValidMAC(mac string) bool {
    pattern := `^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$`
    macRegex := regexp.MustCompile(pattern)
    return macRegex.MatchString(mac)
}

func main() {
    fmt.Println(isValidMAC("00:1A:2B:3C:4D:5E"))  // true
    fmt.Println(isValidMAC("00-1A-2B-3C-4D-5E"))  // true
    fmt.Println(isValidMAC("001A.2B3C.4D5E"))     // false
}


When Should You Use MAC Regex Validation?


  • Device registration systems: Validate MAC IDs during onboarding.

  • Network tools: Ensure clean, usable MAC input before connection setup.

  • IoT and embedded systems: Identify devices with consistency across logs.

  • Security software: Whitelist MACs using regex-based filtering.


Pro Tips for Better MAC Regex Validation


  • Use [0-9a-fA-F] to cover both upper and lowercase.

  • Stick to one separator style (colon or hyphen) within a regex to keep patterns strict.

  • Avoid patterns that allow trailing characters or incorrect segment lengths.

  • If comparing multiple device attributes, try pairing it with the IP Address Generator or UUID Generator.


Useful Metacharacters for MAC Regex


  • ^: Start of string

  • $: End of string

  • [0-9a-fA-F]: Any hex digit (case-insensitive)

  • {2}: Exactly two characters

  • [:-]: Colon or hyphen separator

  • {5}: Repeat 5 times

You can copy this pattern directly into the Go Regex Tester to test your logic live.


Combine with These Tools


Frequently asked questions

What is considered a valid MAC address format?×
A valid MAC address consists of six groups of two hexadecimal characters separated by either colons (:) or hyphens (-). For example: 00:1A:2B:3C:4D:5E or 00-1A-2B-3C-4D-5E.
Will the regex work if I use lowercase letters in the MAC address?+
Can I use mixed separators like colon and hyphen in one address?+
What happens if I input more or fewer groups than required?+
Does this validator support Cisco-style MAC addresses with dots?+