Google Interview Question

Write a regular expression to match a machine's MAC address

Interview Answers

Anonymous

Sep 25, 2010

The regex above is for an IP address, not a MAC address. One possible regex for a MAC address is ([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])

Anonymous

Oct 21, 2010

And if you're allowed to use Perl regex, you could flag case-insensitivity: /^([0-9A-F]{2}:){5}[0-9A-F]{2}$/i

Anonymous

Sep 22, 2010

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b