Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: pattern matching

by Athanasius (Monsignor)
on Oct 12, 2012 at 15:42 UTC ( #998727=note: print w/ replies, xml ) Need Help??


in reply to pattern matching

Hello perltux, and welcome to the Monastery!

How do I get the second pattern match to assign all matches as multiple elements to the array?

I think you need to capture the multiple matches first, then separate them using a loop:

my @chunks = $sysex_dump =~ /\xF0C.[~z]((?:..LM 0087[A-Z][A-Z].+?)+)\ +xF7/gs; my @parts; for (@chunks) { push @parts, $1 while /(..LM 0087[A-Z][A-Z].+?)/gs; }

This code is untested (you provided no sample data), but it should give you a workable approach. Note that in the first regex, the second + quantifier needs to be within the capturing parentheses, so I have added non-capturing parentheses (?:) to define this quantifier’s scope.

Update: I see you have added a “self contained code example” to your original post. From this, it appears that the data to be matched contains literal . characters (periods, full stops.) But your regex matches these with:

(..LM 0087[A-Z][A-Z].+?) # ^^ <= here they are

which matches any two characters. To match periods only, backslash them in the regex:

/\xF0C.[~z](\.\.LM 0087[A-Z][A-Z].+?)+\xF7/s

Hope that helps,

Athanasius <°(((><contra mundum


Comment on Re: pattern matching
Select or Download Code
Re^2: pattern matching
by perltux (Beadle) on Oct 12, 2012 at 16:14 UTC
    Thanks,looks like this works but it's very contrived, surely there must be an easier way to do it all in on go?
Re^2: pattern matching
by perltux (Beadle) on Oct 12, 2012 at 18:39 UTC
    I have tried this now but unfortunately it still doesn't work, the second match in the line starting with 'push' matches too few bytes, it needs to match all bytes until the next occurence of (..LM 0087A-ZA-Z.+?). If I remove the '?' at the end then it matches all occurrences at once. How do I get this match right to match all bytes until the next occurence of (..LM 0087A-ZA-Z.+?) ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998727]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2014-08-22 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (158 votes), past polls