Use the MAC Address Regex Python Validator to test and validate MAC address formats using Python’s re module. This tool is essential for developers working on network configuration, device authentication, or IoT systems. Combine it with the IP Address Regex Python Validator for dual-layer validation in network-heavy apps, or integrate it with the UUID Regex Python Validator when handling device identifiers across systems.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
What is a MAC Address Regex?
A MAC (Media Access Control) address is a unique identifier assigned to a device’s network interface. It typically looks like 01:23:45:67:89:AB or 01-23-45-67-89-AB, composed of six pairs of hexadecimal digits.
To validate MAC addresses using regex, we use a pattern that ensures the correct grouping, delimiter, and character format.
MAC Address Regex Pattern (Python)
This pattern validates:
6 hexadecimal pairs separated by either colons (:) or hyphens (-)
Both uppercase and lowercase letters (A-F, a-f)
Strict format with no extra characters
How to Validate MAC Address in Python
Here’s how you can use the re module in Python to validate MAC addresses:
Examples
Valid
AA:BB:CC:DD:EE:FF
aa-bb-cc-dd-ee-ff
Invalid
AA:BB:CC:DD:EE
AABB.CCDD.EEFF
GG:HH:II:JJ:KK:LL
Use Cases
IoT and Embedded Systems: Validate MAC addresses during device provisioning.
Network Security: Filter and whitelist specific MAC formats in firewalls.
Form Validation: Ensure valid MAC input in Python-based admin tools or APIs.
Batch File Processing: Use alongside the Python Regex Tester for cleaning large datasets with device records.
Pro Tips
Flexible Delimiters: If your input could contain both : and -, keep the current pattern. For one specific format only, remove the alternate.
Case Insensitivity: This pattern works for both uppercase and lowercase letters. No need for .lower() conversions.
Additional Check: Pair with the IP Address Regex Python Validator to fully verify network device entries.
Avoid Typos: Add a pre-validation step to strip extra whitespace using .strip() in Python before applying the regex.