Search code examples
regex

What is a regular expression for a MAC Address?


In this format:

3D:F2:C9:A6:B3:4F

or:

3D-F2-C9-A6-B3-4F

Solution

  • The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits, separated by hyphens - or colons :.

    So:

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