Re: how to repeat non-atom patterns



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

.



Relevant Pages

  • Re: re module non-greedy matches broken
    ... Regex patterns are expressed positive by ... Modern regular expression engines (which are no longer regular ... there are some common patterns on how to write some specific ... AFAICS one needs non-greedy regexps very very rarely at all. ...
    (comp.lang.python)
  • Re: Isolate lines in a text file and perform replacement
    ... Perl and regular expressions to normalize the file names. ... applying these regex patterns to playlist and xml files. ... The script performs a recursive search and finds files with these ...
    (comp.unix.shell)
  • Re: how to repeat non-atom patterns
    ... a regex that repeat the patterns(which is non-atom) 6 times. ...
    (perl.beginners)
  • Re: Nesting while loops
    ... patterns in preset files separated by whitespace. ... allows me to have presets for renaming folders, mp3, html, php, or css ... the same regex expression file can be use to ... I would be careful piping into a loop in Bash, ...
    (comp.unix.shell)
  • Re: selecting Strategy by regex
    ... > I need to parse HTML pages; which parser I use is determined ... > thru the list all the time and evaluate each regex until one does match. ... have several thousand patterns, I can't speak for how the regexp parser ... group the subpatterns using parens and then use Matcher.groupto ...
    (comp.lang.java.programmer)