MAC addresses
A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.
The task
The whole line must match. Match a MAC address: six pairs of hex digits (0 to 9, a to f, either case) separated by colons, like 00:1A:2b:3C:4d:5E.
What this exercise teaches
(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2} counts the pairs exactly. \w{2} would let g through, and a class like [0-9A-Fa-f:]{17} would accept the colons in the wrong places.
A hint if you get stuck
Repeat a group of two hex digits and a colon five times, then add the last pair without a colon.
Try it now, free, no account needed
Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.
Open this exerciseMore exercises in Real-world validation
- US ZIP and ZIP+4Free
- US phone number formatsFree
- Dates YYYY-MM-DDFree
- 24-hour times HH:MMFree
- 12-hour times with AM or PMFree
- Simple email addressesFree
- Hex colorsFree
- IPv4 addresses, 0 to 255Free
- URL slugsFree
- SKU codesFree
- Currency amounts with commasFree
- Semantic versionsFree
- UUIDsFree
- Percentages from 0 to 100Free