Validation
Match a MAC address
Match MAC addresses in colon or hyphen separated form.
Pattern
Regular expression
(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}How it works
Matches the two most common MAC address formats: colon-separated (Linux/macOS) and hyphen-separated (Windows). Six pairs of hex digits with a consistent separator.
Matches
- ▸00:1A:2B:3C:4D:5E
- ▸00-1A-2B-3C-4D-5E
- ▸ff:ff:ff:ff:ff:ff
Non-matches
- ▸00:1A:2B:3C:4D (5 groups)
- ▸GG:1A:2B:3C:4D:5E
Common gotchas
This accepts a mix of separators (`00:1A-2B:3C:4D:5E`). To force consistency, use a capture group backreference: `([0-9A-Fa-f]{2})([:-])(?:[0-9A-Fa-f]{2}\\2){4}[0-9A-Fa-f]{2}`.
Language snippets
JavaScript
const re = /(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}/g;Python
re.findall(r"(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}", text)Go
re := regexp.MustCompile(`(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}`)Java
Pattern.compile("(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}")Related patterns
Match an IPv4 address
(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)
Match an IPv6 address
(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}|::1|::
Match an email address
[\w.+-]+@[\w-]+\.[\w.-]+
Match a URL
https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*
Match a UUID (v4)
[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
Match a US phone number
(?:\+?1[-. ]?)?\(?[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}