in reply to Problem with capturing all matches with regex

(...)+ only returns the last match. That's how quantified capture brackets behave. Use /g and while if you want to do something with the pairs:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $equation = '979x + 87y - 8723z = 274320'; my @parts; push @parts, "[$1 $2]" while $equation =~ /(.*?)([xyz])\s*/gi; say for @parts;

Or assing directly to the array:

my @parts = $equation =~ /(.*?)([xyz])\s*/gi; say for @parts;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Problem with capturing all matches with regex
by igoryonya (Pilgrim) on Oct 12, 2016 at 15:07 UTC
    So, this means, I have to do it this way (according to my updated version):
    my $equation = '979x + 87y - 8723z = 274320'; my @parts = ($equation =~ /(.*?)([xyz])/ig); push(@parts, ($equation =~ /\G(.*)=(.*)/));
    Too bad, I thought, I could do it in one swipe.
      ... do it in one swipe.

      See tybalt89's post for a one-swiper. If you don't like the  grep defined, ... before the array assignment and if you have Perl version 5.10+ which supports the  (?| ... | ... ) "branch reset" grouping, there's this:

      c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use 5.010; ;; my $equation = '979x + 87y - 8723z = 274320'; my @parts = $equation =~ m{ \G (?| (.*?)([xyz]) | (.*) = (.*) \z) }xm +sig; dd \@parts; " [979, "x", " + 87", "y", " - 8723", "z", " ", " 274320"]

      Update: Please see  "(?|pattern)" in Extended Patterns in perlre.


      Give a man a fish:  <%-{-{-{-<

        Awesome, I am glad, I've posted this question, I've learned so many things about regex, that didn't grasp from several times of rereading various perlre* tuts/docs in perl's documentation.