Regex for MAC Address
Matches MAC addresses in common formats using colons or hyphens as separators (e.g., 00:1A:2B:3C:4D:5E).
Pattern
/^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| ([0-9a-fA-F]{2}[:-]) | Two hex digits followed by colon or hyphen |
| {5} | Repeat 5 times (first 5 octets) |
| [0-9a-fA-F]{2} | Final two hex digits |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| 00:1A:2B:3C:4D:5E | Match |
| 00-1A-2B-3C-4D-5E | Match |
| 001A2B3C4D5E | No match |
| GG:1A:2B:3C:4D:5E | No match |
Common Use Cases
- Network device identification
- DHCP configuration
- Network monitoring
Variations
^[0-9a-fA-F]{12}$12 hex digits without separators
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester