tools / regex library / mac address
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

InputResult
00:1A:2B:3C:4D:5Ematches
AA-BB-CC-DD-EE-FFmatches
fe:ff:ff:ff:ff:ffmatches
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

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  

Related

uuid · html tag · image src in html · ipv4 address