Rob Dixon wrote:
ciwei wrote:
Given a multiple char patterns like ":C9" that repeated, how to write
a regex that repeat the patterns( which is non-atom ) 6 times. like
in below
WWPN:10:00:00:00:c9:2e:e8:90
I tried to define pattern to match
my $match= qr/ {:[0-9a-e][0-9a-e]}{6} /;
print matched if /$match/ ;
but it unable to match. any suggestions.
You need to enclose the subpattern in parentheses. The string you show
will match a regex like this:
'WWPN:10:00:00:00:c9:2e:e8:90' =~ /^WWPN(:[0-9a-f]{2}){8}$/;
but because normal parentheses will cause unnecessary substring
captures, it's better to use the non-capturing structure (?: ... ) so
the regex becomes
/^WWPN(?::[0-9a-f]{2}){8}$/
Hexadecimal is case insensitive so this will probably work better:
/^WWPN(?i::[0-9a-f]{2}){8}$/
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/