在 Notepad++ 中查找 CRLF [英] Find CRLF in Notepad++
问题描述
如何在 Notepad++ 中查找/替换所有 CR/LF 字符?
我正在寻找与 Microsoft Word 中的 ^p 特殊字符等效的东西.
[\r\n]+
应该也能用
更新 2012 年 3 月 26 日,".
(由 georgiecasey 在他/她的下面的答案)
一些相关的摘录包括以下搜索过程:
<块引用>简单搜索 (Ctrl+F),搜索模式 = Normal
您可以在编辑窗口中选择一个EOL
.
- 只需将光标移动到行尾,然后键入 Shift+Right 箭头.
- 或者,用鼠标选择
EOL
,从行尾开始并拖动到下一行的开头;拖动到EOL
的右侧将不起作用.您可以手动复制EOL
并将其粘贴到 Unix 文件字段中(LF
-only).
简单搜索 (Ctrl+F),搜索模式 = 扩展
扩展"选项将 \n
和 \r
显示为可以匹配的字符.
与普通搜索模式一样,Notepad++ 正在寻找确切的字符.
在 UNIX 格式的文件中搜索 \r
不会找到任何东西,但搜索 \n
会.同样,Macintosh 格式的文件将包含 \r
但不包含 \n
.
简单搜索(Ctrl+F),搜索模式=正则表达式
正则表达式使用字符 ^
和 $
将匹配字符串定位到行的开头或结尾.例如,搜索 return;$
将找到return;"的出现发生在同一行上没有后续文本的情况.锚字符在所有文件格式中的作用相同.
这 '.'点元字符与行尾不匹配.
[在 Notepad++ 5.8.5 中测试]:使用显式 \r
或 \n
的正则表达式搜索不起作用(与
在选择EOL时,既不是显式(粘贴的)LF,或在字段中放置在字段中的(不可见)EOL字符上.高级搜索 (Ctrl+R),无需正则表达式
Ctrl+M 将插入与换行符匹配的内容.它们将被替换字符串替换.
我推荐这种方法是最可靠的,除非你真的需要使用正则表达式.
例如,要删除双倍行距文件中的第二个换行符,请在搜索字符串框中输入 Ctrl+M 两次,在替换字符串框中输入一次.>
使用正则表达式进行高级搜索 (Ctrl+R).
Ctrl+M、$
和 \r\n
都不匹配.
<小时>
同一个维基还提到了十六进制编辑器替代方案:
<块引用>- 在文档开头键入新字符串.
- 然后选择以以十六进制模式查看文档.
- 选择其中一行新行并点击 Ctrl+H.
- 当您打开替换"对话框时,在背景上选择新的替换字符串,然后 Ctrl+C 将其复制并粘贴到替换为文本"输入中.
- 然后根据需要替换或全部替换.
注意:为换行选择的字符通常显示为0a
.
如果文件是 Windows 格式,它可能具有不同的值.在这种情况下,您可以随时转到 Edit ->EOL 转换 ->转换为Unix格式
,替换后切换回Edit ->EOL 转换 ->转换为 Windows 格式
.
How can I find/replace all CR/LF characters in Notepad++?
I am looking for something equivalent to the ^p special character in Microsoft Word.
[\r\n]+
should work too
Update March, 26th 2012, release date of Notepad++ 6.0:
OMG, it actually does work now!!!
Original answer 2008 (Notepad++ 4.x) - 2009-2010-2011 (Notepad++ 5.x)
Actually no, it does not seem to work with regexp...
But if you have Notepad++ 5.x, you can use the 'extended' search mode and look for \r\n
. That does find all your CRLF
.
(I realize this is the same answer than the others, but again, 'extended mode' is only available with Notepad++ 4.9, 5.x and more)
Since April 2009, you have a wiki article on the Notepad++ site on this topic:
"How To Replace Line Ends, thus changing the line layout".
(mentioned by georgiecasey in his/her answer below)
Some relevant extracts includes the following search processes:
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 theEOL
won't work. You can manually copy theEOL
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 forreturn;$
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 regexpCtrl+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.
The same wiki also mentions the Hex editor alternative:
- 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 toEdit -> EOL Conversion -> Convert to Unix Format
, and after the replacement switch it back andEdit -> EOL Conversion -> Convert to Windows Format
.
这篇关于在 Notepad++ 中查找 CRLF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!