Regex for MAC address
/\b[0-9A-Fa-f]{2}(?:([:-])[0-9A-Fa-f]{2})(?:\1[0-9A-Fa-f]{2}){4}\b/g
Matches
Examples
Note
The backreference \1 makes every separator match the first, so mixed colons and dashes are rejected.
Matches in the example
"00:1A:2B:3C:4D:5E""00-1a-2b-3c-4d-5f"
Token by token
\ba word boundary[0-9A-Fa-f]{2}one of: “0” to “9”, “A” to “F” or “a” to “f”, exactly 2 times(?:a group, not capturing(a capturing group[:-]one of: “:” or “-”)end of group[0-9A-Fa-f]{2}one of: “0” to “9”, “A” to “F” or “a” to “f”, exactly 2 times)end of group(?:a group, not capturing\1the same text group 1 matched[0-9A-Fa-f]{2}one of: “0” to “9”, “A” to “F” or “a” to “f”, exactly 2 times){4}end of group, whole group exactly 4 times\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma