Advertisement

Pattern library / Validation

MAC Address Regex (EUI-48)

A MAC address is six groups of two hex digits — aa:bb:cc:dd:ee:ff — and every tool has a separator opinion: Windows shows dashes, Linux shows colons, some capture tools nothing at all. This pattern accepts colon and dash forms in one shot; the notes cover the no-separator and Cisco dotted variants.

The pattern
^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
aa:bb:cc:dd:ee:ffMatchlowercase, colon-separated (Linux)Try →
AA-BB-CC-DD-EE-FFMatchuppercase, dash-separated (Windows)Try →
00-1A-2B-3C-4D-5EMatchvendor OUI with digitsTry →
aabb.ccdd.eeffNo matchCisco dotted format — alternative in notesTry →
aabbccddeeffNo matchno separators — different patternTry →
aa:bb:cc:dd:eeNo matchfive groups onlyTry →

Where to use it

JavaScript

const MAC = /^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/;
MAC.test('aa:bb:cc:dd:ee:ff'); // true
MAC.test('aa:bb:cc:dd:ee');    // false

Python (audit a list)

import re
MAC = r'^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$'
valid = [l.strip() for l in open('macs.txt') if re.fullmatch(MAC, l.strip())]

Bash (grep, colon-only)

grep -E '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$' arp.txt

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

How do I match MAC addresses without separators?

^[0-9a-fA-F]{12}$ — exactly twelve hex digits. Convert incoming formats to one canonical form (usually lowercase colon-separated) before comparing anything.

Why does my pattern only match five groups?

The repeat count is {5} plus a final pair: six pairs total. A {4} or {6} copy-paste is the classic off-by-one — count the groups in your failing input first.

Does this work in GA4 or BigQuery?

Yes — plain classes and quantifiers, valid RE2. Device inventory usually lives in logs or BigQuery rather than GA4, but the pattern is portable everywhere.

IPv4 Address Regex — Validate Dots & Octets · UUID Regex — Match Any UUID (1-5) Format · Log Level Regex — Match INFO / WARN / ERROR Lines

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.