Skip to main content
Network & Web · In-Browser Regular Expression Lab

MAC Address Regex — Colon and Hyphen Hardware Addresses

Matches 6-byte IEEE 802 Media Access Control (MAC) hardware addresses with colons or hyphens.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:00:1A:2B:3C:4D:5E

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

00:1A:2B:3C:4D:5E Pass
a1-b2-c3-d4-e5-f6 Pass
FF:FF:FF:FF:FF:FF Pass

Expected Invalid Samples (Must Reject)

00:1A:2B:3C:4D Rejected (Pass)
00:1A:2B:3C:4D:5E:6F Rejected (Pass)
00:1Z:2B:3C:4D:5E Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})$/;
const text = "00:1A:2B:3C:4D:5E";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Validates six pairs of hexadecimal characters separated by colons or hyphens. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
[0-9A-Fa-f]{2}Hex byteTwo hexadecimal digits.
[:-]SeparatorEither a colon or a hyphen.
{5}Repeat 5 timesMatches first five separated bytes.

Frequently Asked Questions

How to support Cisco format (xxxx.xxxx.xxxx)?
Use `^(?:[0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4}$`.
Browse All 40 Patterns