我如何才能找到/替换所有CR/LF字符在notepad++ ?

我正在寻找一些相当于微软Word中的^p特殊字符。


假设它有一个“正则表达式”搜索,寻找\r\n。我更喜欢\r?\n,因为一些文件不使用回车。

编辑:感谢你的反馈,无论谁投了反对票。我了解到……没有,因为你没有提供任何反馈。为什么这是错误的?

[\r\n]+也可以

2012年3月26日更新,notepad++ 6.0发布日期:

天哪,它现在真的有用了!!


原答案2008 (notepad++ 4.x) - 2009-2010-2011 (notepad++ 5.x)

实际上不,它似乎不能与regexp一起工作…

但是如果你有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:

Use the "View | Show end of line" menu to enable display of end of line characters. (Carriage return line feeds should show up as a single shaded CRLF 'character'.) Select one of the CRLF 'characters' (put the cursor just in front of one, hold down the SHIFT key, and then pressing the RIGHT CURSOR key once). Copy the CRLF character to the clipboard. Make sure that you don't have the find or find/replace dialog open. Open the find/replace dialog. The 'Find what' field shows the contents of the clipboard: in this case the CRLF character - which shows up as 2 'box characters' (presumably it's an unprintable character?) Ensure that the 'Regular expression' option is 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版本。

将一个由多行组成的文档改为一行,每行组成逗号分隔的列表中的一个条目:

按Ctrl +f打开搜索/替换。 点击“替换”页签。 用“\r\n”填充“Find what”条目。 用“,”或“,”(取决于偏好)填充“Replace with”条目。 取消选中“匹配整个单词”复选框(回避逻辑的重要部分)。 检查“扩展”单选按钮。 点击“全部替换”按钮。

这些步骤转向。

foo酒吧 酒吧巴兹 巴兹foo

成:

Foo bar,bar baz,baz Foo

或者:(取决于个人喜好)

Foo bar, bar baz, baz Foo

如果你需要做一个复杂的regexp替换,包括\r\n,你可以通过三步方法来解决这个限制:

将所有的\r\n替换为一个标签,例如#GO#→检查'Extended',将\r\n替换为#GO# 执行regexp,例如从html书签中删除多行ICON="*"→检查regexp,替换ICON=.[^"]+。> by > 返回\r\n→勾选“扩展”,将#GO#替换为\r\n

我在notepad++中打开文件,并在几个步骤中进行替换:

将所有“\r\n”替换为“\r\n” 替换所有”;“\r\n”和“\r\n” 将所有“\r\n”替换为“”

这将把所有的断点放在它们应该在的位置,并删除那些破坏文件的断点。

这对我很管用。

也许你可以使用TextFX插件

在TextFX中,点击TextFX编辑→删除空行

在2013年v6.13或更高版本中,使用:

菜单编辑→EOL转换→Windows格式。

CRLF图像


不含CRLF的图像

只需在find中执行\r,并在replace字段中使用空白进行替换,这样所有内容都将上升到一行。然后执行查找和替换(在我的例子中是分号)并替换为;\n

:) -条款和条件

做这个设置。菜单->视图->显示符号->取消勾选显示行结束

我在NP v6.9中完全无法做到这一点。 我发现用微软的Word (2K)软件就足够简单了。

打开文档,点击编辑->replace。

然后在搜索框的底部,点击“更多”,然后找到“特别”按钮,他们有一些东西给你。对于Dos样式,我使用“段落”样式。这是一双橱窗里的cr。

进入查看—>显示符号—>显示所有字符 //这招对我很管用

要找到任何类型的换行序列,请使用以下正则表达式结构:

\R

要查找和选择连续的换行序列,在\R: \R+后添加+。

确保你打开了正则表达式模式:

它匹配:

U+000DU+000A -CRLF '序列 U+ 000a -换行,lf U+ 000b -行制表,vt U+ 000c -形式馈电,ff U+ 000d -回车,cr U+0085 -下一行,nel U+2028线分隔器 U+2029段分隔符