1

I am parsing some logged text which contains a series of similar event updates. The events are logged similar to my example below, where they all begin and end with the exact same text and have unique text in between.

I need to be able to match between "process started" and "process completed successfully", but there could exist a case when one process doesn't complete successfully. In this case I do not want a match because we see 2 instances of "process started" prior to seeing "process completed". I believe this regex is close, but messes up on the second example text.

(process started).*?(process id \d{2}).*?(?<!process started).*?(process completed) https://regex101.com/r/RhY2Kj/1

Example where each process section is correctly matched:

process started
process id 00
some process details, many lines
process completed  # this block is match 1

process started
process id 01
other process details, many lines
process completed  # this block is match 2

Error in the log causes improper match. My regex matches this entire block of text, but I do not want it to:

process started
process id 00         # this block shouldn't match anything
some process details  # because process completed is missing

process started
process id 01
other process details
process completed  # this block should match
Ken White
  • 123,280
  • 14
  • 225
  • 444

0 Answers0