简体   繁体   English

Notepad++ 有选择地删除文件中的行

[英]Notepad++ Selectively delete lines within a file

I have a dual.srt file that looks like this:我有一个看起来像这样的 dual.srt 文件:

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).我想删除所有俄语行(加上相应的 CRLF)。 Which means lines 4, 9, 14, 19, 24, 29, and so on.这意味着第 4、9、14、19、24、29 行等。 It's every 5 lines, starting at line 4.从第 4 行开始,每 5 行一次。

I guess Notepad++'s "Find in files" should be able to do it with the right RegEx (but I'm open to any solution).我猜 Notepad++ 的“在文件中查找”应该能够使用正确的 RegEx 来完成(但我愿意接受任何解决方案)。 Could you please help me with that?你能帮我解决这个问题吗? Thank you.谢谢你。

To target every nth line in non empty line sequences:以非空行序列中的每 n 行为目标:

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

See this demo at regex101 (explanation on right side)请参阅 regex101 上的此演示(右侧说明)

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.+原子组更有效的替代方案: (?>\R?.+){3}\K\R.+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM