find-in-files icon indicating copy to clipboard operation
find-in-files copied to clipboard

Find a result that involve more lines in the file

Open FulvioSpelta opened this issue 6 years ago • 0 comments

Hi all, I kindly ask for a support. I need to search in mid-size text files (one at the time, 50/60 MB size) for regexp that search for 2 strings one "near" the other. The use case is to automatically search for patterns (request/answer) in log files.

Example: text file fragment

000000: USB-SERIAL CH340 (COM12), 2018-11-26 17:35:54,3748068
 0A 03 00 00 00 17 04 BF                           .......¿
000001: USB-SERIAL CH340 (COM10), 2018-11-26 17:35:54,9676068 +0,5928000
 0A 03 2E 00 01 00 00 00 18 00 18 00 19 00 18 00   ................
 19 00 31 00 01 00 01 00 01 00 01 01 CC 70 DE C3   ..1.........ÌpÞÃ
 4F 95 02 00 00 00 00 00 00 00 00 00 00 00 00 0C   O•..............
 B7 E5 45                                          ·åE

First i search for the request pattern using theexample code with this "regexp" and i find the expected result:

findInFiles.find({'term': "0A 03 00 00 00 17 04 BF", 'flags': 'gm'}, '.', '.txt$')
found "0A 03 00 00 00 17 04 BF" 752 times in "181127_0944_ReqView.txt"

Then i search for the req/ans pattern where the result involve search in multiple lines and it finds nothing:

findInFiles.find({'term': "0A 03 00 00 00 17 04 BF\W+(?:\w+\W+){1,40}? 0A 03 2E", 'flags': 'gm'}, '.', '.txt$')

Using the same regexp in notepad++ search returns the expected results: image

Can someone kindly give me an hint (i'm not an expert programmer i'm writing just few lines of code to automate field tests) ? Thanks a lot

FulvioSpelta avatar Nov 28 '18 07:11 FulvioSpelta