Search code examples
regexnotepad++

How to Bookmark Lines Before and After a Target Line Until a Specific Separator in Notepad++?


I have some text like following:

-------------------------------------------------------------
2021-05-18 - Tortrettert.webm 521.483
"Totrrtp" : 5 times
"GDtretP" : 17 times
-------------------------------------------------------------
2021-06-25 - Cghtytryrtyhtjyuj.webm 480.0
"Certhiltertdren" : 2 times
"Berterorn" : 1 times
"Woertmartn" : 4 times
"higerthesertertt" : 66 times
"birrtertths" : 5 times
"woertertmrtertan_" : 1 times
-------------------------------------------------------------
2021-06-26 - Thytyrtytyng.webm 536.999
"Edtryucytryated" : 2 times
"Avrtyertyrtyage" : 2 times
"Yertyartys" : 4 times
"Strychootrylrtying" : 2 times
-------------------------------------------------------------
2021-06-27 - Wortyrtyrthtyts.webm 552.016
"Coffytryhtyjee" : 11 times
-------------------------------------------------------------
2021-06-29 - Moshrhtyjykuyukjity.webm 485.966
"Potrhwhrthetyjrful" : 16 times
"Artrhmithrres" : 2 times
"Nurthctrhlearthr" : 8 times
"Catrhtrhpabrthilrthity" : 1 times
-------------------------------------------------------------

Now I want to bookmark all lines before and after : 1 times until -------------------------------------------------------------

I tried following regex:

^.*: 1 times.*$(?s)(?:(?!^-{61}$).)*^-{61}$

This regex works well, but it has a problem. It only bookmarks lines after the target line and does not bookmark lines before target line until the specific separator.
where is my regex problem?

I want to bookmark following lines in sample:

-------------------------------------------------------------
2021-06-25 - Cghtytryrtyhtjyuj.webm 480.0
"Certhiltertdren" : 2 times
"Berterorn" : 1 times
"Woertmartn" : 4 times
"higerthesertertt" : 66 times
"birrtertths" : 5 times
"woertertmrtertan_" : 1 times
-------------------------------------------------------------
-------------------------------------------------------------
2021-06-29 - Moshrhtyjykuyukjity.webm 485.966
"Potrhwhrthetyjrful" : 16 times
"Artrhmithrres" : 2 times
"Nurthctrhlearthr" : 8 times
"Catrhtrhpabrthilrthity" : 1 times
-------------------------------------------------------------

Solution

  • You could use this find/replace command Ctrl+H:

    Find what: ^-+\R((?!---).*(?<! 1 times)\R)*(?=-+$)
    Replace with:

    Search mode:
    ⦿ Regular expression     ☐ . matches newline

    Replace All

    (So don't tic the ". matches newline" box).