E-Scribe : a programmer’s blog

About Me

PBX I'm Paul Bissex. I build web applications using open source software, especially Django. Started my career doing graphic design for newspapers and magazines in the '90s. Then wrote tech commentary and reviews for Wired, Salon, Chicago Tribune, and others you never heard of. Then I built operations software at a photography school. Then I helped big media serve 40 million pages a day. Then I worked on a translation services API doing millions of dollars of business. Now I'm building the core platform of a global startup accelerator. Feel free to email me.

Book

I co-wrote "Python Web Development with Django". It was the first book to cover the long-awaited Django 1.0. Published by Addison-Wesley and still in print!

Colophon

Built using Django, served with gunicorn and nginx. The database is SQLite. Hosted on a FreeBSD VPS at Johncompanies.com. Comment-spam protection by Akismet.

Pile o'Tags

Stuff I Use

bitbucket, Django, Emacs, FreeBSD, Git, jQuery, LaunchBar, Markdown, Mercurial, OS X, Python, Review Board, S3, SQLite, Sublime Text, Ubuntu Linux

Spam Report

At least 236325 pieces of comment spam killed since 2008, mostly via Akismet.

A MAC address regex

Today I worked on a form and script used for registering users on a restricted-access wireless network. Here's a nice compact regex for checking that MAC addresses have been entered in the correct format. (If you're using this in a double-quoted PHP string, escape the "$" with a backslash.)

/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/i

Friday, September 8th, 2006
+
5 comments

Comment from Bjoern , 8 months later

Hi,

great regex! exactly what I was looking for.

It only does not match lower case also the windows output of ipconfig/all (using a dash as delimiter) is not covered

here's my addition: /^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i

Comment from Paul , 8 months later

Thanks for the update, Bjoern. The "/i" modifier at the end already makes it case-insensitive (assuming you're using Perl-compatible regexes), but adding the dash as a separator is a good improvement.

Comment from Jeremy , 4 years later

Thanks for this!

Added support for no separator...

/^([0-9A-F]{2}[:-]{0,1}){5}[0-9A-F]{2}$/i

Comment from Manohar Bhattarai , 5 years later

This link might give you all more insight. http://manoharbhattarai.wordpress.com/2012/02/17/regex-to-match-mac-address/

Comment from Manohar , 5 years later

Great regex. I have a link that explains to match all 3 types of mac addresses http://manoharbhattarai.wordpress.com/tag/regex-to-find-mac-address/

Comments are closed for this post. But I welcome questions/comments via email or Twitter.