in reply to pattern matching (greedy, non-greedy,...)
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pattern matching (greedy, non-greedy,...)
by cacophony777 (Initiate) on Dec 17, 2009 at 01:22 UTC | |
by AnomalousMonk (Archbishop) on Dec 17, 2009 at 01:52 UTC | |
by AnomalousMonk (Archbishop) on Dec 17, 2009 at 02:15 UTC |