in reply to Problem with capturing all matches with regex

I changed 3 things:

use warnings; use strict; use Data::Dumper; my $equation = '979x + 87y - 8723z = 274320'; my @parts = ($equation =~ /(?:(.*?)([xyz]))/ig); print Dumper(\@parts); __END__ $VAR1 = [ '979', 'x', ' + 87', 'y', ' - 8723', 'z' ];

Tip #9 from the Basic debugging checklist ... YAPE::Regex::Explain

Replies are listed 'Best First'.
Re^2: Problem with capturing all matches with regex
by igoryonya (Pilgrim) on Oct 12, 2016 at 14:44 UTC
    OK, I've abbreviated my problem @ first, but your answer suggested, that I should tell the whole story, as why I didn't use /g, for example.
    I've updated my original post.
      #!/usr/bin/perl -l # http://perlmonks.org/?node_id=1173839 use strict; use warnings; my $equation = '979x + 87y - 8723z = 274320'; #my @parts = ($equation =~ /^(?:(.*?)([xyz]))+/i); my @parts = grep defined, $equation =~ /(.*?)([xyz])|(.*?)=(.*)/gi; use Data::Dumper; print Dumper \@parts;