Re: how to repeat non-atom patterns
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Fri, 28 Mar 2008 00:03:12 +0000
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}$/
HTH,
Rob
.
- Follow-Ups:
- Re: how to repeat non-atom patterns
- From: John W. Krahn
- Re: how to repeat non-atom patterns
- References:
- how to repeat non-atom patterns
- From: Ciwei
- how to repeat non-atom patterns
- Prev by Date: Re: Handling OLD files
- Next by Date: Re: Handling OLD files
- Previous by thread: Re: how to repeat non-atom patterns
- Next by thread: Re: how to repeat non-atom patterns
- Index(es):
Relevant Pages
|
|