regexhelper
Test a pattern. Copy a ready-made one. No signup.

Regex to Match a MAC Address

Copy the pattern, paste your text below, and see every MAC address it finds. Below the tester: how it accepts both colon and hyphen separators.

/ /

What this pattern matches

This matches a 48-bit MAC address written as six pairs of hex digits separated by colons or hyphens.

How it works, part by part

[0-9a-fA-F]{2} — one octet: two hex digits.

[:-] — a colon or hyphen separator.

(?:…){5} — five octet-plus-separator groups, then one final octet.

Mixed separators

This will technically accept a mix of colons and hyphens in one address. If you need consistency, capture the first separator with a backreference: ([:-])(?:[0-9a-fA-F]{2}\1){4}….

FAQ

Does it accept hyphen-separated MACs?

Yes. The [:-] class allows both 01:23:… and 01-23-… forms.

Will it match a 5-octet string?

No. It requires exactly six octets, so a shorter run fails the boundary.

How do I forbid mixed separators?

Use a capture group and backreference so every separator must match the first one.