gettoolz.app

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.

Pattern^[0-9a-f]{2}([:-])[0-9a-f]{2}(?:\1[0-9a-f]{2}){4}$
JavaScript literal/^[0-9a-f]{2}([:-])[0-9a-f]{2}(?:\1[0-9a-f]{2}){4}$/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.

Inputs tested against the MAC address regex
InputResultWhy
00:1a:2b:3c:4d:5ePassescolon-separated
00-1A-2B-3C-4D-5EPasseshyphen-separated, as Windows prints it
00:1a-2b:3c:4d:5eFailsmixed separators
001a.2b3c.4d5eFailsCisco dotted form
001a2b3c4d5eFailsno separators
00:1a:2b:3c:4dFailsfive pairs
00:1a:2b:3c:4d:5gFailsg 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

Or open the regex tester empty and bring your own pattern.