MAC Address Regex
Validates a 48-bit MAC address written as six hexadecimal byte pairs separated by colons or hyphens, such as 00:1A:2B:3C:4D:5E.
Regex Pattern
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the very start of the string. |
| [0-9A-Fa-f]{2} | Exactly two hexadecimal digits, forming one byte of the address. |
| [:-] | A single separator character: either a colon or a hyphen. |
| {5} | Repeats the preceding hex-pair-plus-separator group exactly five times. |
| ([0-9A-Fa-f]{2}) | Captures the sixth and final hex pair, which has no trailing separator. |
| $ | Anchors the match to the very end of the string. |
Detailed Explanation
What it does
This pattern checks that a string is a well-formed 48-bit MAC (Media Access Control) address made of six two-digit hexadecimal octets. It accepts either colon-separated (00:1A:2B:3C:4D:5E) or hyphen-separated (00-1A-2B-3C-4D-5E) notation, which are the two conventions used by most operating systems and network tools.
Why it works
The core building block `[0-9A-Fa-f]{2}` matches exactly one byte expressed as two hex digits. Wrapping it with a separator and repeating that group five times via `{5}` accounts for the first five octets, and a final standalone hex-pair group closes out the sixth octet without a trailing separator. Anchoring with `^` and `$` guarantees the entire string, not just part of it, conforms to the shape.
Common use cases
- Validating MAC addresses entered in network configuration forms
- Filtering or parsing DHCP lease logs and ARP tables
- Sanitizing device identifiers before storing them in a database
- Client-side validation for router or IoT device admin panels
Edge cases
- Mixed separators like 00:1A-2B:3C-4D:5E will still match because each group's separator is checked independently
- Uppercase, lowercase, and mixed-case hex digits are all accepted (00:1a:2B:3c:4D:5e)
- A MAC address with dot notation (0011.2233.4455), common on Cisco devices, will not match
- Leading or trailing whitespace causes the match to fail because of the strict anchors
Limitations
- Does not enforce a single consistent separator across all groups
- Does not recognize Cisco-style dot-grouped notation (aaaa.bbbb.cccc)
- Does not validate whether the address is a real, assigned, or locally-administered MAC (e.g. multicast bit checks)
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const macPattern = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
function isValidMac(address) {
return macPattern.test(address);
}
console.log(isValidMac("00:1A:2B:3C:4D:5E")); // trueCommon Mistakes
Forgetting that colons and hyphens can be mixed because each separator is matched independently per group.
Fix: If you need a single consistent separator, capture the first separator and use a backreference, e.g. `^([0-9A-Fa-f]{2})([:-])(?:[0-9A-Fa-f]{2}\2){4}[0-9A-Fa-f]{2}$`.
Assuming this pattern also matches Cisco's dot-grouped notation like 0011.2233.4455.
Fix: Add a separate alternative branch for the dotted format if you need to support Cisco-style addresses.
Not anchoring the pattern and accidentally matching a MAC address embedded inside a longer string.
Fix: Keep the `^` and `$` anchors, or use `\b` word boundaries if you intentionally want to search within larger text.
Performance Notes
- The pattern has no unbounded quantifiers or nested repetition, so it runs in linear time with no catastrophic backtracking risk.
- The fixed `{5}` repetition count keeps the engine's work bounded regardless of input length beyond the expected size.
- Anchoring with `^` and `$` lets the engine fail fast on inputs of the wrong length instead of scanning further.
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |
Work with this pattern
Take this expression further — test it against your own data, adapt it in the builder, or read up on the syntax behind it.
Regex Tester
Test a regular expression against sample text and see every match highlighted live.
Regex Generator
Build a pattern by clicking blocks — no syntax memorisation required.
Regular Expressions Guide
What regex is, how the syntax works, and the mistakes that trip people up.
Regex Cheat Sheet
Every token, quantifier, and assertion on one printable page.
Python Regex Guide
The re module end to end — search, match, findall, groups, and substitution.
Regex Pattern Library
100+ ready-to-use patterns for email, URLs, dates, IPs, and more.