# Regex for MAC Addresses

> MAC address regex for AA:BB:CC:DD:EE:FF and AA-BB-CC-DD-EE-FF forms, with variations for consistent separators and Cisco dot notation. Explained token by token.

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

A MAC address is six bytes written as hex pairs. This pattern accepts colon- or hyphen-separated forms in either case. It doesn't insist that all five separators match, so a mixed address like 00:1A-2B:3C:4D:5E passes — the first variation fixes that with a backreference.

## Token by token

| Token | Meaning |
|---|---|
| `^` | start of string |
| `(?:[0-9A-Fa-f]{2}[:-]){5}` | five hex pairs, each followed by a colon or a hyphen |
| `[0-9A-Fa-f]{2}` | the sixth pair, with no separator after it |
| `$` | end of string |

## Examples

- ✓ matches: `00:1A:2B:3C:4D:5E`
- ✓ matches: `00-1a-2b-3c-4d-5e`
- ✓ matches: `FF:FF:FF:FF:FF:FF`
- ✗ does not match: `00:1A:2B:3C:4D`
- ✗ does not match: `001A2B3C4D5E`
- ✗ does not match: `00:1G:2B:3C:4D:5E`

## Variations

- `^[0-9A-Fa-f]{2}([:-])(?:[0-9A-Fa-f]{2}\1){4}[0-9A-Fa-f]{2}$` — the separator must be the same throughout (backreference \1)
- `^(?:[0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4}$` — Cisco dotted form: 001a.2b3c.4d5e

## Language notes

- Backreferences like \1 work in JavaScript, Python, PCRE and Java. Go's RE2 engine doesn't support them — use the base pattern there and compare the separators in code.

## FAQ

### Should I accept MAC addresses without separators?

Many tools print them bare (001A2B3C4D5E). Normalise input first — strip colons, hyphens and dots — then check for exactly 12 hex digits with ^[0-9A-Fa-f]{12}$.

### Does this check that the MAC address is real?

No. Any 12 hex digits pass, including the broadcast address (FF:FF:FF:FF:FF:FF) and locally administered addresses. Use it for format validation only.

## Related patterns

- [Regex for IPv4 Address Validation](https://www.devkult.com/regex/ipv4.md)
- [Regex for IPv6 Address Validation](https://www.devkult.com/regex/ipv6.md)
- [Regex for Hex Color Codes](https://www.devkult.com/regex/hex-color.md)

Open the interactive page: https://www.devkult.com/regex/mac-address