Regex for MAC Address
Regex Pattern
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$MAC address with colons or dashes as separators
Quick Answer
The regex pattern for mac address is `^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$`. MAC address with colons or dashes as separators. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 00:1B:44:11:3A:B7 | ✓ Matches |
| 00-1B-44-11-3A-B7 | ✓ Matches |
| aa:bb:cc:dd:ee:ff | ✓ Matches |
| 00:1B:44:11:3A | ✗ No match |
| 001B44113AB7 | ✗ No match |
| 00:1B:44:11:3A:G7 | ✗ No match |
Code Examples
javascript
const regex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
const isValid = regex.test(value);python
import re
pattern = r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/', $value)) {
echo "valid";
}java
String pattern = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
IPv4 Address
Validates a well-formed IPv4 address (0-255 in each octet)
IPv6 Address
Basic IPv6 address (8 groups of 4 hex digits)
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
URL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs
URL (Any Protocol)
Matches URLs with any protocol (http, https, ftp, ws, etc.)