Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Regular Expression for MAC Address

by jrynz (Initiate)
on May 20, 2007 at 02:12 UTC ( [id://616378]=note: print w/replies, xml ) Need Help??


in reply to Regular Expression for MAC Address

Try this one:
((?:(\d{1,2}|[a-fA-F]{1,2}){2})(?::|-*)){6}
Example Usage (extract MAC address):
my $string = 'tu0 1500 <Link> 00-00-f8-05-c8-20'; $string =~ m/^.+ ( # Start back reference capture for MAC Address ((?:(\d{1,2}|[a-fA-F]{1,2}){2})(?::|-*)){6} ) # End back reference $/xms; print "$1\n" if (defined $1);
NB: This will also work with MAC like:
my $string = 'tu0   1500  <Link>  00:00:f8:05:c8:20';

Replies are listed 'Best First'.
Re^2: Regular Expression for MAC Address
by Anonymous Monk on Mar 24, 2011 at 17:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://616378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-29 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found