Here's an approach to use if you have all the 'log lines' as a single (possibly quite long) string as mention of KEY.*PATTERN in your OP suggests:
>perl -wMstrict -le "my $s = 'KE a KE bb ccc KE ddd PA ee KE fff xx PA gg KEPA h'; my $start = qr{ KE }xms; my $not_start = qr{ (?! $start) . }xms; my $stop = qr{ PA }xms; my $chunk = qr{ $start $not_start* $stop }xms; print qq{'$s'}; print map qq{'$_' }, $s =~ m{ $chunk }xmsg; " 'KE a KE bb ccc KE ddd PA ee KE fff xx PA gg KEPA h' 'KE ddd PA' 'KE fff xx PA' 'KEPA'
This won't work if you are processing the file line-by-line. I'm working on that as, no doubt, are others.
Update: ... like toolic.
It should be mentioned that if if you are processing a multi-line file slurp, the $start and $stop regexes should be something like qr{ ^ KE $ }xms and qr{ ^ PA $ }xms respectively – note the ^ $ embedded newline anchor metacharacters.
In reply to Re: pattern matching (greedy, non-greedy,...)
by AnomalousMonk
in thread pattern matching (greedy, non-greedy,...)
by cacophony777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |