cacophony777 has asked for the wisdom of the Perl Monks concerning the following question:
I've been trying to write a script to generate some useful output based on a log file, and I ran into the issue mentioned in this thread.
http://www.nntp.perl.org/group/perl.perl6.language.regex/2000/12/msg507.html
Specifically, the problem I'm trying to solve involves matching a group of log lines.
For example:
KEY blah blahblah KEY blah ah other random stuff KEY blah ha other random stuff PATTERN asdf KEY fdas PATTERN
I want to match each PATTERN, but have the match also include the most recent preceeding KEY (and everything in between). So these are the two matches I'm interested in:
KEY blah ha other random stuff PATTERN
KEY fdas PATTERN
If I do something like KEY.*PATTERN the entire contents get the match, and if I do KEY.*?PATTERN it matches everything from the first KEY to the first PATTERN. I've also tried .*KEY.+?PATTERN which just matches the very last group.
If you've got any insight it would be greatly appreciated.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern matching (greedy, non-greedy,...)
by toolic (Bishop) on Dec 17, 2009 at 00:51 UTC | |
by ikegami (Patriarch) on Dec 17, 2009 at 02:22 UTC | |
|
Re: pattern matching (greedy, non-greedy,...)
by AnomalousMonk (Archbishop) on Dec 17, 2009 at 00:44 UTC | |
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 | |
|
Re: pattern matching (greedy, non-greedy,...)
by Skeeve (Parson) on Dec 17, 2009 at 09:57 UTC | |
|
Re: pattern matching (greedy, non-greedy,...)
by AnomalousMonk (Archbishop) on Dec 17, 2009 at 15:21 UTC |