[英]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 上的此演示(右侧说明)
\A
matches start of the string \A
匹配字符串的开头\R
matches any newline sequence \R
匹配任何换行符序列\K
resets beginning of the reported match \K
重置报告匹配的开始.+
matches one or more of any character (besides newline) .+
匹配一个或多个任意字符(换行符除外)(?:
non capturing group )
{3}
quantified three times (?:
non capture group )
{3}
量化了 3 次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.