in reply to Problem with capturing all matches with regex
You've got a couple of issues there. By making it a bit simpler, and adding the /g (global match) flag, it seems to work.
The ^ means match only at the beginning of the string, so you'll only get a single match, even with global flag set, and the (?:) non-capture grouping isn't required.
my $equation = '979x + 87y - 8723z = 274320'; # catch anything that proceeds an x, y or z, and then # catch that letter as well into another capture group my @parts = ($equation =~ /(.*?)([xyz])/ig); print "$_\n" for @parts;
Output:
979 x + 87 y - 8723 z
|
|---|