perltux has asked for the wisdom of the Perl Monks concerning the following question:
Hi, given the same identical input string, why does the following line return an array with 2 elements:
my @parts=($sysex_dump =~ /\xF0C.[~z](..LM 0087[A-Z][A-Z].+?)(..LM 0087[A-Z][A-Z].+?)\xF7/gs);While this line only returns an array with the first of the above two elements:
my @parts=($sysex_dump =~ /\xF0C.[~z](..LM 0087[A-Z][A-Z].+?)+\xF7/gs);I would have thought the '+' after the bracket should match more than once and assign all matches to the array?
How do I get the second pattern match to assign all matches as multiple elements to the array?
Edited to add a self contained code example (the print and the for loop are just to check the array I get):
my @parts=("\xF0C.z..LM 0087AAaaa..LM 0087BBbbb\xF7"=~ /\xF0C.[~z](. +.LM 0087[A-Z][A-Z].+?)+\xF7/s); print STDERR @parts." parts\n"; for($a = 0; $a < @parts; $a++) { print STDERR ($a+1).": ".length($parts[$a])." length\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern matching
by choroba (Cardinal) on Oct 12, 2012 at 14:57 UTC | |
by Athanasius (Archbishop) on Oct 12, 2012 at 16:09 UTC | |
by perltux (Monk) on Oct 12, 2012 at 16:12 UTC | |
|
Re: pattern matching
by nemesdani (Friar) on Oct 12, 2012 at 14:56 UTC | |
|
Re: pattern matching
by Athanasius (Archbishop) on Oct 12, 2012 at 15:42 UTC | |
by perltux (Monk) on Oct 12, 2012 at 16:14 UTC | |
by perltux (Monk) on Oct 12, 2012 at 18:39 UTC |