regex pattern · ready to copy
Regex for matching MAC addresses
Standard 6-octet MAC with `:` or `-` separators. Case-insensitive hex.
intermediate
javascript / pcre / python4 use cases
The pattern
[0-9A-Fa-f]{2}(?:[:-][0-9A-Fa-f]{2}){5}
Test cases
| Input | Result |
|---|---|
| 00:1A:2B:3C:4D:5E | ✓matches |
| AA-BB-CC-DD-EE-FF | ✓matches |
| fe:ff:ff:ff:ff:ff | ✓matches |
| 001A2B3C4D5E (no separators) | ✗rejects |
| 00:1A:2B:3C:4D (too short) | ✗rejects |
Edge cases & caveats
Cisco's `0011.2233.4455` dotted format requires separate alternation: `[0-9A-Fa-f]{4}(?:\.[0-9A-Fa-f]{4}){2}`. Multicast bit detection needs first-octet check.
Common use cases
- network device inventory
- DHCP log scraping
- ARP cache parsing
- wireless audit
Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab