MAC Address in PY
Match 48-bit MAC addresses written with colon or hyphen separators (e.g. 00:1A:2B:3C:4D:5E).
Try it in the PY tester →Pattern
regexPY
(?:[0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2} (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"(?:[0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}")
input_text = "00:1A:2B:3C:4D:5E"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
Five pairs of hex digits each followed by : or -, then a final hex pair. Case-insensitive by character class to handle both upper and lower hex digits.
Examples
Input
00:1A:2B:3C:4D:5EMatches
00:1A:2B:3C:4D:5E
Input
AA-BB-CC-DD-EE-FFMatches
AA-BB-CC-DD-EE-FF
Input
not a macNo match
—