MAC AddressRegex — Pattern, Examples & Code
^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$What it matches / doesn't match
| Matches ✅ | Does not match ❌ |
|---|---|
●00:1A:2B:3C:4D:5E | ●00:1A:2B:3C:4D |
●AA-BB-CC-DD-EE-FF | ●001A2B3C4D5E |
●de:ad:be:ef:00:01 | ●GG:HH:II:JJ:KK:LL |
How it works
Matches 48-bit MAC addresses in the standard six-octet format with either colons or hyphens as separators. Each octet must be exactly two hex digits (0–9, A–F). The separator must be consistent — this pattern allows mixing colons and hyphens, so add a backreference if you need strict consistency.
Code Usage
JavaScript
const regex = /^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$/;
regex.test("00:1A:2B:3C:4D:5E"); // truePython
import re
pattern = re.compile(r'^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$')
bool(pattern.match("00:1A:2B:3C:4D:5E")) # TrueGo
import "regexp"
r := regexp.MustCompile(`^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$`)
r.MatchString("00:1A:2B:3C:4D:5E") // trueNeed a custom regex for a different use case?
Generate a custom regex with AI →FAQ
What does the MAC Address regex pattern match?
Matches 48-bit MAC addresses in the standard six-octet format with either colons or hyphens as separators. Each octet must be exactly two hex digits (0–9, A–F). The separator must be consistent — this pattern allows mixing colons and hyphens, so add a backreference if you need strict consistency.
How do I use the MAC Address regex in JavaScript?
const regex = /^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$/; regex.test("00:1A:2B:3C:4D:5E"); // true
Can I use the MAC Address regex in Python?
Yes. import re pattern = re.compile(r'^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$') bool(pattern.match("00:1A:2B:3C:4D:5E")) # True
