Search code examples
regexnotepad++

Notepad++ Selectively delete lines within a file


I have a dual .srt file that looks like this:

1
00:07:14,120 --> 00:07:16,953
[French line]
[Russian line]

2
00:07:16,960 --> 00:07:19,952
[French line]
[Russian line]

3
00:07:21,240 --> 00:07:24,835
[French line]
[Russian line]

I would like to delete all the Russian lines (plus the corresponding CRLF's). Which means lines 4, 9, 14, 19, 24, 29, and so on. It's every 5 lines, starting at line 4.

I guess Notepad++'s "Find in files" should be able to do it with the right RegEx (but I'm open to any solution). Could you please help me with that? Thank you.


Solution

  • To target every nth line in non empty line sequences:

    (?:(?:\R|\A).+){3}\K\R.+
    

    See this demo at regex101 (explanation on right side)

    Click on "replace all" and replace with empty.
    Make sure to uncheck [ ] dot matches newline in the replace dialogue.
    A bit more efficient alternative with atomic group: (?>\R?.+){3}\K\R.+