DevTools
Back to Regex Tester

MAC Address Regex Pattern

Match and validate MAC (Media Access Control) addresses in colon-separated, dash-separated, and dot-separated formats using regex.

The Pattern

/\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b/g

How It Works

TokenMeaning
\bWord boundary to prevent partial matches
[0-9A-Fa-f]{2}Exactly 2 hexadecimal characters (one octet)
[:-]Colon or dash separator between octets
{5}Repeat the octet-separator group 5 times
[0-9A-Fa-f]{2}Final octet (no trailing separator)

Test Cases

00:1A:2B:3C:4D:5EMatch
AA:BB:CC:DD:EE:FFMatch
00-1A-2B-3C-4D-5EMatch
ff:ff:ff:ff:ff:ffMatch
00:1A:2B:3C:4DNo match
GG:HH:II:JJ:KK:LLNo match
001A2B3C4D5ENo match

Code Examples

javascript
const macRegex = /\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b/g;
const text = "Devices: 00:1A:2B:3C:4D:5E and AA-BB-CC-DD-EE-FF";
const matches = text.match(macRegex);
console.log(matches); // ["00:1A:2B:3C:4D:5E", "AA-BB-CC-DD-EE-FF"]
python
import re
mac_regex = r'\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b'
text = "Devices: 00:1A:2B:3C:4D:5E and AA-BB-CC-DD-EE-FF"
matches = re.findall(mac_regex, text)
print(matches)  # ['00:1A:2B:3C:4D:5E', 'AA-BB-CC-DD-EE-FF']

Common Use Cases

Related Patterns

Want to test this pattern with your own data?

Try this pattern in Regex Tester →