PatternRegex

Match a MAC address

Match hardware MAC addresses in the six-pair colon or dash notation — for log greps, inventory sheets and DHCP configs.

Last updated

Patterng
(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}
Open in Regex Tester & Builder

Matches

  • 00:1A:2B:3C:4D:5E
  • 00-1a-2b-3c-4d-5e

Doesn’t match

  • 00:1A:2B:3C:4D
  • 001A.2B3C.4D5E

Why it’s written this way

Five "pair plus separator" groups and a final bare pair gives exactly six octets. The [:-] class accepts both the Unix colon convention and the Windows dash convention in one pattern.

Edge cases to know

  • Mixed separators (00:1A-2B:3C-4D:5E) match, since each position chooses independently — validate consistency separately if it matters.
  • Cisco's dotted-quad form (001a.2b3c.4d5e) is a different shape and needs its own alternative.
  • It says nothing about whether the address is real — for vendor lookup, drop it into the MAC Address Analyzer tool.

Related in Patterns