Find in Files (Regex) - Returning Consecutive Lines

90 Views Asked by At

I need to return all occurrences of when three lines are consecutively written in a file. I'm looking for the following:

FieldName=<some name>
Operator=<some operator>
Value=<some value>

Example File Content

MatchAny=FALSE
FieldValue=TRUE
Operator=Is less than
TotalFields=1
[OutputTarget0SelField0]
FieldName=ORIG-DATE
Operator=Is greater than
Value=20000101
[OutputTarget1]

To do this, I have been trying to use Notepad++ Find in Files functionality but I cannot seem to get the correct regular expression.

Here is what I've tried (in this case I'm assuming the two lines after FieldName= will always be Operator= and Value=)

enter image description here

Find what: (FieldName=|Operator=|Value) is also close, but obviously doesn't account for the fact that these lines need to be consecutive ("FieldName=" followed by "Operator=" followed by "Value=") and returns all single occurrences as well.

1

There are 1 best solutions below

0
Sebastian Proske On

You can use ^FieldName=[^\n\r]*[\n\r]+Operator=[^\n\r]*[\n\r]+Value=[^\n\r]* to match your 3 consectuve lines:

  • ^FieldName=[^\n\r]*[\n\r]+ matches a start of a line, follwed by FieldName=, any amount of non-linebreaks and then one or more linbreaks. As you tagged your question with Windows, you might be able to replace [\n\r]+ with \r\n, this also prevents empty lines from jumping into the match (which at the moment would be possible)
  • Operator=[^\n\r]*[\n\r]+ is basically the same for the Operator-Line
  • Value=[^\n\r]* is again the same for the Value-Line, this time without the finishing linebreaks

As stated in the comments, this will only show you the first matched line in the find in files overview, but you can double click it, so it shows the whole match.