Skip to main content
CalcHive

Regex for MAC Address

Matches MAC addresses in common formats using colons or hyphens as separators (e.g., 00:1A:2B:3C:4D:5E).

Pattern

/^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/

Pattern Breakdown

TokenExplanation
^Start of string
([0-9a-fA-F]{2}[:-])Two hex digits followed by colon or hyphen
{5}Repeat 5 times (first 5 octets)
[0-9a-fA-F]{2}Final two hex digits
$End of string

Test Examples

InputMatch?
00:1A:2B:3C:4D:5EMatch
00-1A-2B-3C-4D-5EMatch
001A2B3C4D5ENo match
GG:1A:2B:3C:4D:5ENo match

Common Use Cases

  • Network device identification
  • DHCP configuration
  • Network monitoring

Variations

^[0-9a-fA-F]{12}$

12 hex digits without separators

Want to test this pattern with your own data?

Open the Regex Tester