Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Regular Expression for MAC Address

by jrynz (Initiate)
on May 20, 2007 at 02:12 UTC ( #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';


Comment on Re: Regular Expression for MAC Address
Select or Download Code
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
Node Status?
node history
Node Type: note [id://616378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-10-01 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (38 votes), past polls