MAC Address Regex Pattern
Validates MAC addresses in colon or hyphen-separated format with 6 groups of 2 hexadecimal digits.
Live Regex Tester
Pattern Breakdown
Code Examples
JavaScript
const regex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
const test = "00:1A:2B:3C:4D:5E";
console.log(regex.test(test)); // true
// Extract matches
const matches = test.match(regex);
console.log(matches);Python
import re
pattern = r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
test = "00:1A:2B:3C:4D:5E"
match = re.search(pattern, test)
print(match) # Found!Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$`)
fmt.Println(re.MatchString("00:1A:2B:3C:4D:5E")) // true
}Common Use Cases
Match Examples
| Input | Result |
|---|---|
| 00:1A:2B:3C:4D:5E | Match |
| 00:1A:2B | No Match |
About the MAC Address Regex
Validates MAC addresses in colon or hyphen-separated format with 6 groups of 2 hexadecimal digits.
Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The mac address pattern is classified as beginner difficulty in the validation category. It works in all major programming languages.
When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.
More Validation Patterns
Need More Regex Patterns?
Browse our complete library of 100+ regex patterns with interactive testers.
Frequently Asked Questions
What is the MAC Address regex pattern?
Validates MAC addresses in colon or hyphen-separated format with 6 groups of 2 hexadecimal digits.
How do I use the MAC Address regex?
Use the pattern /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/ in your code. In JavaScript: new RegExp('^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$', ''). Test it above with your own input.
What does this MAC Address regex match?
This pattern matches: "00:1A:2B:3C:4D:5E". It does NOT match: "00:1A:2B". Network device identification, DHCP management, security auditing.
Is the MAC Address regex beginner-friendly?
This pattern is rated Beginner. It uses basic regex syntax and is easy to understand.
What languages support the MAC Address regex?
This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.
Can I modify the MAC Address regex for my use case?
Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.