in reply to Re^2: Problem with capturing all matches with regex
in thread Problem with capturing all matches with regex
... 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: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Problem with capturing all matches with regex
by igoryonya (Pilgrim) on Oct 13, 2016 at 01:25 UTC |