MAC Address in JS
Match 48-bit MAC addresses written with colon or hyphen separators (e.g. 00:1A:2B:3C:4D:5E).
Try it in the JS tester →Pattern
regexJS
(?:[0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2} (flags: g)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("(?:[0-9A-Fa-f]{2}[:\\-]){5}[0-9A-Fa-f]{2}", "g");
const input = "00:1A:2B:3C:4D:5E";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
Five pairs of hex digits each followed by : or -, then a final hex pair. Case-insensitive by character class to handle both upper and lower hex digits.
Examples
Input
00:1A:2B:3C:4D:5EMatches
00:1A:2B:3C:4D:5E
Input
AA-BB-CC-DD-EE-FFMatches
AA-BB-CC-DD-EE-FF
Input
not a macNo match
—