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.
In reply to pattern matching (greedy, non-greedy,...) by cacophony777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |