[rt-users] regex for mac address

Gene LeDuc gleduc at mail.sdsu.edu
Wed Jun 2 17:44:47 EDT 2010

Hi Troy,

The format for MAC addresses is not standardized.  I've seen them with 
(Win, RedHat) and without (Solaris) leading zeros, colons (RH, Solaris) 
or hyphens (Win) as separators, and uppercase (Win, RedHat) or lowercase 
(Solaris) hex values.  I think I've also seen network gear that shows 
them as xxxx:xxxx:xxxx.  It really depends on where the MAC info is 
coming from.

These may not be perfect, but you get the idea.

WXP: /^([0-9a-f]{2}-){5}[0-9a-f]{2}$/i
RH: /^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i
Sol: /^(([0-9a-f]|[1-9a-f][0-9a-f]):){5}([0-9a-f]|[1-9a-f][0-9a-f])$/i

You could try normalizing the string by replacing all colons with 
hyphens and then adding a leading zero to all single character values, 
and then applying your regex.


On 6/2/2010 2:06 PM, Troy Knabe wrote:
> I am trying to do a regex for mac address verification. My first attempt
> looks like this, but did not work. Anyone have any insight as to what I
> am missing?
> ^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}$
> --
> Troy Knabe
> knabe at 4j.lane.edu <mailto:knabe at 4j.lane.edu>

More information about the rt-users mailing list