Search for API Security Tests

Mac Address Regex Python Validator

Mac Address Regex Python Validator

Regex Tester Online tools to learn, build & test Regular Expression (RegEx/RegExp)
0 match
/ gm
Possible security issues
Match information

Regular Expression - Documentation

Regular Expression - Documentation


Validating MAC addresses in Python is important in network programming and hardware interfacing. Python's re module can be used for regex-based MAC address validation. A common regex pattern for this is ^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$.

What is MAC Address Regex?

The regex pattern for a MAC address checks the standard format: six groups of two hexadecimal digits.

The MAC Address Regex Pattern

  • Pattern: ^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$

  • This matches MAC addresses with colon : or hyphen `` separators.

How to Validate MAC Addresses in Python?

To validate MAC addresses using regex in Python:

import re

def is_valid_mac_address(mac):
    mac_regex = re.compile(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')
    return bool(mac_regex.match(mac))

test_mac = "01:23:45:67:89:AB"
print(f"Is '{test_mac}' a valid MAC address? {is_valid_mac_address(test_mac)}")

Uses of MAC Address Regex Validation

  1. Network Configuration: Ensuring MAC addresses are correctly formatted in network setups.

  2. Hardware Interfacing: Validating MAC addresses in software dealing with physical network devices.


Python’s regex capabilities make it well-suited for MAC address validation, ensuring standard format adherence. For more complex scenarios or varied formats, Akto's regex validator can provide additional validation flexibility.

Frequently asked questions

Why is validating MAC addresses important in network programming?

What is the regex pattern for validating MAC addresses in Python?

Can MAC addresses have different formats?

How can I validate MAC addresses in Python?

Are MAC addresses case-sensitive in Python validation?

Mac Address Regex Python Validator



Mac Address Regex Python Validator