简体   繁体   English

使用Notepad ++从文件中删除每第二行

[英]Deleting every 2nd line from a file using Notepad++

I am looking for some regex help. 我正在寻找一些正则表达式的帮助。

I have a textfile, nothing super important but I would like to delete every second line from it - I have tried following this guide: Delete every other line in notepad++ 我有一个文本文件,没有什么超级重要,但我想删除它的每一行 - 我试过按照本指南: 删除记事本中的每隔一行++

However I just can't get it to work, is the regex I am using ok? 但是,我无法让它工作,我正在使用正则表达式吗? I am noob with regex 我是正则表达式的noob

Find: 找:

([^\n]*\n)[^\n]*\n

Replace with: 用。。。来代替:

$1

No matter what I try (mouse position at the beginning, ctrl+a and Replace All) I just can't get it to work. 无论我尝试什么(开头的鼠标位置,ctrl + a和全部替换)我都无法让它工作。 I appreciate any help. 我感谢任何帮助。

I've put the regex into here: http://regexpal.com/ and if I remove the final \\n it highlights the individual rows. 我把正则表达式放在这里: http//regexpal.com/如果我删除了最终\\ n它会突出显示各行。

Make sure you select regular expression for the search mode ... 确保为搜索模式选择正则表达式 ...

Also, you may want to make that final newline optional . 此外,您可能希望将最终换行设置为可选 In the case that there are an even number of lines and you do not have a trailing newline, it won't remove the last line. 如果行数为偶数且您没有尾随换行符,则不会删除最后一行。

([^\n]*\n)[^\n]*\n?

Update: 更新:

See how Windows handle new lines with \\r\\n instead of just \\n . 怎么看的Windows处理新线\\r\\n ,而不是仅仅\\n Try updating the expression to take this into account: 尝试更新表达式以将此考虑在内:

([^\r\n]*[\r\n]+)[^\r\n]*[\r\n]*

Final Update: 最后更新:

Thanks to @zx81, I now know that N++ uses PCRE so \\R can be used for unicode newline characters. 感谢@ zx81,我现在知道N ++使用PCRE所以\\R可以用于unicode换行符。 However [^\\R] won't work (this looks for anything except R literally), so you will need to keep [^\\r\\n] . 但是[^\\R]不起作用(这样可以查找除R之外的任何内容),因此您需要保留[^\\r\\n] This can be simplified as : 可以简化为

([^\r\n]*\R)[^\r\n]*\R?

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

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