From web at polynate.net Sat Mar 26 04:00:58 2016 From: web at polynate.net (Nathan Bailey) Date: Sat, 26 Mar 2016 22:00:58 +1100 Subject: [Melbourne-pm] How to parse n matches out of a string? Message-ID: Is there a 'best practice' idiom for parsing out multiple matches from a string, ie. 'blahMatchblah blah blahMatch blah blahMatchblah' Previously I've done: while (my ($match,$rest) = $string =~ m#(Match)(.*)) { $string = $rest; } which works, but seems inelegant. Is there a better/recommended way? cheers, Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From damian at conway.org Sat Mar 26 04:30:09 2016 From: damian at conway.org (Damian Conway) Date: Sat, 26 Mar 2016 22:30:09 +1100 Subject: [Melbourne-pm] How to parse n matches out of a string? In-Reply-To: References: Message-ID: Nathan Bailey asked: > Is there a 'best practice' idiom for parsing out multiple matches from a > string? > my @matches = $string =~ m{ (Match) }gx; HTH, Damian -------------- next part -------------- An HTML attachment was scrubbed... URL: From shlomif at shlomifish.org Sat Mar 26 07:58:44 2016 From: shlomif at shlomifish.org (Shlomi Fish) Date: Sat, 26 Mar 2016 17:58:44 +0300 Subject: [Melbourne-pm] How to parse n matches out of a string? In-Reply-To: References: Message-ID: <20160326175844.2a1e6773@telaviv1.shlomifish.org> Hi all, On Sat, 26 Mar 2016 22:30:09 +1100 Damian Conway wrote: > Nathan Bailey asked: > > > Is there a 'best practice' idiom for parsing out multiple matches from a > > string? > > > > my @matches = $string =~ m{ (Match) }gx; > > HTH, > Damian One should also note that one can use the /g regex-modifier in scalar context in conjuction with pos , /c , etc. For some more comprehensive pages about that and other methods of parsing text, see: * http://perl-begin.org/uses/text-parsing/ * http://perl-begin.org/topics/regular-expressions/ (Note: I originated http://perl-begin.org/ and I still maintain it.) Regards, Shlomi Fish -- Give me ASCII or give me dea?! From web at polynate.net Sun Mar 27 02:52:23 2016 From: web at polynate.net (Nathan Bailey) Date: Sun, 27 Mar 2016 20:52:23 +1100 Subject: [Melbourne-pm] Fwd: How to parse n matches out of a string? In-Reply-To: References: <20160326175844.2a1e6773@telaviv1.shlomifish.org> Message-ID: Thanks all - much more elegant :-) -N On 27 March 2016 at 01:58, Shlomi Fish wrote: > Hi all, > > On Sat, 26 Mar 2016 22:30:09 +1100 > Damian Conway wrote: > > > Nathan Bailey asked: > > > > > Is there a 'best practice' idiom for parsing out multiple matches from > a > > > string? > > > > > > > my @matches = $string =~ m{ (Match) }gx; > > > > HTH, > > Damian > > One should also note that one can use the /g regex-modifier in scalar > context in conjuction with pos , /c , etc. For some more comprehensive > pages > about that and other methods of parsing text, see: > > * http://perl-begin.org/uses/text-parsing/ > > * http://perl-begin.org/topics/regular-expressions/ > > (Note: I originated http://perl-begin.org/ and I still maintain it.) > > Regards, > > Shlomi Fish > > -- > > Give me ASCII or give me dea?! > -------------- next part -------------- An HTML attachment was scrubbed... URL: