[Nh-pm] Regexp help

Kevin D. Clark kclark at CetaceanNetworks.com
Thu Feb 27 15:34:43 CST 2003


pll at lanminds.com writes:

> I'm trying to match a MAC addr in perl with a regex.  This is what 
> I've got so far:
> 
> 	((([0-9A-F]{2}):){5}$1)

In some sense, I can see what you're trying to do with the "$1", but
you should know that if you're trying to do something like this, then
you need to use \1 instead of $1 (due to how internals of the Perl
machine works...).  But you're fundamentally using this wrong anyways
(\1 will match whatever the regex engine matches, not the actual regex
itself)

How about this instead?:

  (?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2}

or, if you wanted to make your code look neat, you could do something
like this:

  $hexre = '(?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2}';

  ($macaddr) = /$hexre/o;

...which I think is something like what you were trying to do in the
first place.

Hope this helps,

--kevin
-- 
Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA)
cetaceannetworks.com!kclark (GnuPG ID: B280F24E)
alumni.unh.edu!kdc




More information about the Nh-pm mailing list