from re import search, MULTILINE match = search(r"(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})", out, MULTILINE) if match: return match.group(0)