Hello tj999,
When you find a match, you don’t want to consume the whole matched part of the string, since then you’ll miss every second match. You want to consume only the first half (i.e., the first line) of the match, and start looking again at the beginning of the next line. For this you need a positive lookahead assertion, which prevents the second half of the matched text from being consumed:
use strict; use warnings; my $in = '123,-->456, 456,-->234, 234,-->789, 789,-->123, '; print "$1,-->$2\n" while $in =~ / (\d{3}) ,--> \d{3}, \s+ (?= \d{3} ,--> (\d{3}) ) /g +sx; # | lookahead assertion |
Output:
16:28 >perl 1814_SoPW.pl 123,-->234 456,-->789 234,-->123 16:28 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Multi Line Regex Matches...
by Athanasius
in thread Multi Line Regex Matches...
by tj999
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |