0

Example: I want to match the error block with lines that begin with processing and end with error saving data. The issue I run into is either with greedy or lazy match, regex matches previous values too!

Processing employee 123 1504 of 2056 
2016-12-09-15.14.57.000000 : Employee 123 created.

Processing employee 234 1505 of 2056 
2016-12-09-15.14.57.000000 : Employee 234 created.

Processing employee 345  1506 of 2056
Valid ZIP codes range between 01000 and 99999.
Error saving data.

Processing employee 445 1507 of 2056
2016-12-09-15.14.58.000000 : Employee 445 created.

Processing employee 775 1509 of 2056
warning 123
warning 123
error 123
Error saving data.
Ram
  • 3
  • 1

1 Answers1

0

Use a global match that starts at "Processing employee" and ends with "Error saving data", but make sure there are no two linefeeds in the matched string:

(Processing employee)(\n[^\n]|[^\n])*\n(Error saving data\.)

You can look at the regex at https://regex101.com/r/aCJ2Wv/1

msrd0
  • 7,816
  • 9
  • 47
  • 82
  • Thank you. Make sense. Never thought solving it as a two newlines. I was trying with lookaround assertions. – Ram Dec 12 '16 at 18:55