T
ToolPrime

Regex for MAC Address

Validates MAC addresses in colon or hyphen-separated format.

Pattern

/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i

Live Tester

Enter a string to test

Examples

The i flag makes the pattern case-insensitive.

00:1A:2B:3C:4D:5E
AA-BB-CC-DD-EE-FF
01:23:45:67:89:ab
00:1A:2B:3C:4D
GG:HH:II:JJ:KK:LL
001A2B3C4D5E

Pattern Breakdown

([0-9A-Fa-f]{2}[:-]){5} — five hex pairs with separator

([0-9A-Fa-f]{2})$ — final pair

Code Snippets

Javascript

/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i.test("00:1A:2B:3C:4D:5E"); // true

Python

bool(re.match(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", "00:1A:2B:3C:4D:5E", re.I))  # True

Php

preg_match('/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i', "00:1A:2B:3C:4D:5E"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for MAC Address?
The regex pattern for MAC Address is /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/i. Validates MAC addresses in colon or hyphen-separated format.
How do I use the MAC Address regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the MAC Address pattern match?
It matches strings like 00:1A:2B:3C:4D:5E; it rejects strings like 00:1A:2B:3C:4D. See the Examples section above for the full list of matching and non-matching cases.

Related Tools