MAC address regex
Six pairs of hex digits separated by colons or by hyphens — the same separator throughout, enforced by a back-reference. Copy the pattern, with 2 inputs it accepts and 5 it rejects, each checked against it at build time.
Part of developer tools.
^[0-9a-f]{2}([:-])[0-9a-f]{2}(?:\1[0-9a-f]{2}){4}$/^[0-9a-f]{2}([:-])[0-9a-f]{2}(?:\1[0-9a-f]{2}){4}$/iFlags: i
What the mac address regex accepts and rejects
Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.
| Input | Result | Why |
|---|---|---|
| 00:1a:2b:3c:4d:5e | Passes | colon-separated |
| 00-1A-2B-3C-4D-5E | Passes | hyphen-separated, as Windows prints it |
| 00:1a-2b:3c:4d:5e | Fails | mixed separators |
| 001a.2b3c.4d5e | Fails | Cisco dotted form |
| 001a2b3c4d5e | Fails | no separators |
| 00:1a:2b:3c:4d | Fails | five pairs |
| 00:1a:2b:3c:4d:5g | Fails | g is not a hex digit |
Limits
- The capture group holds the separator so that \1 can require it again; that is why the tester lists a group for every match.
- The Cisco dotted form and bare twelve-digit form are refused. Normalise to one notation before storing.
- EUI-64 identifiers (eight pairs) are not covered.
Try it on your own input
Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.
Other common regexes
- Email address
- URL
- UUID
- IPv4 address
- Hex color
- ISO 8601 date
- 24-hour time
- Semantic version
- URL slug
- Phone number (E.164)
- US ZIP code
Or open the regex tester empty and bring your own pattern.