在记事本中查找CRLF ++
如何在记事本++中查找/替换所有CR / LF字符?
我正在寻找与Microsoft Word中的^ p特殊字符等效的东西。
解决方案
假设它具有"正则表达式"搜索,请查找\ r \ n。我更喜欢\ r?\ n,因为某些文件不使用回车符。
编辑:感谢反馈,任何人对此表示反对。我了解到...好吧,什么都没有,因为我们没有提供任何反馈。为什么会这样呢?
[\ r \ n] +
也应该起作用
2012年3月26日更新,Notepad ++ 6.0的发布日期:
天哪,它实际上确实可以正常工作了!!!
原始答案2008(Notepad ++ 4.x)2009-2010-2011(Notepad ++ 5.x)
实际上不,它似乎不适用于正则表达式...
但是,如果我们使用的是Notepad ++ 5.x,则可以使用"扩展"搜索模式并查找" \ r \ n"。那确实找到了所有的" CRLF"。
(我意识到这是与其他答案相同的答案,但同样,"扩展模式"仅适用于Notepad ++ 4.9、5.x及更高版本)
从2009年4月开始,我们在Notepad ++网站上有关于此主题的Wiki文章:
"如何更换线端,从而改变线布局"。
(由georgiecasey在下面的回答中提到)
一些相关的摘录包括以下搜索过程:
Simple search (`Ctrl`+`F`), Search Mode = Normal You can select an EOL in the editing window. Just move the cursor to the end of the line, and type `Shift`+`Right` Arrow. or, to select EOL with the mouse, start just at the line end and drag to the start of the next line; dragging to the right of the EOL won't work. You can manually copy the EOL and paste it into the field for Unix files (LF-only). Simple search (Ctrl+F), Search Mode = Extended The "Extended" option shows \n and \r as characters that could be matched. As with the Normal search mode, Notepad++ is looking for the exact character. Searching for \r in a UNIX-format file will not find anything, but searching for \n will. Similarly, a Macintosh-format file will contain \r but not \n. Simple search (Ctrl+F), Search Mode = Regular expression Regular expressions use the characters ^ and $ to anchor the match string to the beginning or end of the line. For instance, searching for return;$ will find occurrences of "return;" that occur with no subsequent text on that same line. The anchor characters work identically in all file formats. The '.' dot metacharacter does not match line endings. [Tested in Notepad++ 5.8.5]: a regular expression search with an explicit \r or \n does not work (contrary to the Scintilla documentation). Neither does a search on an explicit (pasted) LF, or on the (invisible) EOL characters placed in the field when an EOL is selected. Advanced search (`Ctrl`+`R`) without regexp `Ctrl`+`M` will insert something that matches newlines. They will be replaced by the replace string. I recommend this method as the most reliable, unless you really need to use regex. As an example, to remove every second newline in a double spaced file, enter `Ctrl`+`M` twice in the search string box, and once in the replace string box. Advanced search (`Ctrl`+`R`) with Regexp. Neither `Ctrl`+`M`, $ nor \r\n are matched.
同一维基还提到了十六进制编辑器的替代方法:
Type the new string at the beginning of the document. Then select to view the document in Hex mode. Select one of the new lines and hit `Ctrl`+`H`. While you have the Replace dialog box up, select on the background the new replacement string and `Ctrl`+`C` copy it to paste it in the Replace with text input. Then Replace or Replace All as you wish. Note: the character selected for new line usually appears as 0a. It may have a different value if the file is in Windows Format. In that case you can always go to Edit -> EOL Conversion -> Convert to Unix Format, and after the replacement switch it back and Edit -> EOL Conversion -> Convert to Windows Format.
在"替换"对话框上,要将搜索模式设置为"扩展"。正常或者正则表达式模式将不起作用。
然后,只需找到" \ r \ n"(对于unix文件,仅找到\ n;对于Mac格式文件,仅找到\ r),然后将替换设置为所需的值即可。
我在查找/替换窗口中对\ r \ n正则表达式不太满意。
但是,这在Notepad ++ v4.1.2中有效:
- 使用"查看|显示行尾"菜单可以显示行尾字符。 (回车换行符应显示为一个带阴影的CRLF"字符"。)
- 选择一个CRLF"字符"(将光标放在一个字符的前面,按住SHIFT键,然后按一下RIGHT CURSOR键)。
- 将CRLF字符复制到剪贴板。
- 确保我们没有打开"查找"或者"查找/替换"对话框。
- 打开查找/替换对话框。 "查找内容"字段显示剪贴板的内容:在这种情况下,CRLF字符-显示为2个"框字符"(大概是不可打印的字符?)
- 确保"正则表达式"选项为OFF。
现在,我们应该可以根据需要进行计数,查找或者替换了。
使用高级搜索选项(Ctrl + R)并使用CRLF的键盘快捷键(Ctrl + M)插入回车符。
看来这是一个常见问题解答,并且提供的解决方案是:
Simple search (Ctrl+H) without regexp You can turn on View/Show End of Line or view/Show All, and select the now visible newline characters. Then when you start the command some characters matching the newline character will be pasted into the search field. Matches will be replaced by the replace string, unlike in regex mode. Note 1: If you select them with the mouse, start just before them and drag to the start of the next line. Dragging to the end of the line won't work. Note 2: You can't copy and paste them into the field yourself. Advanced search (Ctrl+R) without regexp Ctrl+M will insert something that matches newlines. They will be replaced by the replace string.
我发现它起作用的方式是使用"替换"功能,并在"扩展"模式下使用" \ n"。我正在使用5.8.5版。