在Notepad ++中查找CRLF

本文翻译自:Find CRLF in Notepad++

How can I find/replace all CR/LF characters in Notepad++? 如何在Notepad ++中查找/替换所有CR / LF字符?

I am looking for something equivalent to the ^p special character in Microsoft Word. 我正在寻找与Microsoft Word中的^ p特殊字符相当的东西。


#1楼

参考:https://stackoom.com/question/Yqj/在Notepad-中查找CRLF


#2楼

Assuming it has a "regular expressions" search, look for \\r\\n. 假设它有一个“正则表达式”搜索,请查找\\ r \\ n。 I prefer \\r?\\n, because some files don't use carriage returns. 我更喜欢\\ r?\\ n,因为有些文件不使用回车。

EDIT: Thanks for the feedback, whoever voted this down. 编辑:感谢您的反馈,无论是谁投票。 I have learned that... well, nothing, because you provided no feedback. 我已经了解到......好吧,没有,因为你没有提供反馈。 Why is this wrong? 为什么这是错的?


#3楼

[\\r\\n]+ should work too [\\r\\n]+应该有效

Update March, 26th 2012, release date of Notepad++ 6.0 : 更新2012年3月26日, Notepad ++ 6.0的发布日期:

OMG, it actually does work now!!! 天哪,它现在确实有效!!!

Notepad ++中的PCRE regexp


Original answer 2008 (Notepad++ 4.x) - 2009-2010-2011 (Notepad++ 5.x) 原始答案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 . 但是如果你有Notepad ++ 5.x,你可以使用' 扩展 '搜索模式并查找\\r\\n That does find all your CRLF . 这确实找到了你所有的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) (我意识到这是与其他答案相同的答案,但同样,“扩展模式”仅适用于Notepad ++ 4.9,5.x等)


Since April 2009, you have a wiki article on the Notepad++ site on this topic: 自2009年4月起,您在Notepad ++网站上有关于此主题的Wiki文章:
" How To Replace Line Ends, thus changing the line layout ". 如何替换线端,从而改变线路布局 ”。
(mentioned by georgiecasey in his/her answer below ) georgiecasey下面的回答中提到)

Some relevant extracts includes the following search processes: 一些相关摘录包括以下搜索过程:

Simple search ( Ctrl + F ), Search Mode = Normal 简单搜索( Ctrl + F ),搜索模式= Normal

You can select an EOL in the editing window. 您可以在编辑窗口中选择EOL

  • Just move the cursor to the end of the line, and type Shift + Right Arrow. 只需将光标移动到该行的末尾,然后键入Shift + 向右箭头。
  • or, to select EOL with the mouse, start just at the line end and drag to the start of the next line; 或者,要使用鼠标选择EOL ,请从行尾开始并拖动到下一行的开头; dragging to the right of the EOL won't work. 拖动到EOL的右侧将无法正常工作。 You can manually copy the EOL and paste it into the field for Unix files ( LF -only). 您可以手动复制EOL并将其粘贴到Unix文件的字段中( LF -only)。

Simple search (Ctrl+F), Search Mode = Extended 简单搜索(Ctrl + F),搜索模式=扩展

The "Extended" option shows \\n and \\r as characters that could be matched. “扩展”选项将\\n\\r为可以匹配的字符。
As with the Normal search mode, Notepad++ is looking for the exact character. 与普通搜索模式一样,Notepad ++正在寻找确切的字符。
Searching for \\r in a UNIX-format file will not find anything, but searching for \\n will. 在UNIX格式文件中搜索\\r \\n将找不到任何内容,但搜索\\n将会找到。 Similarly, a Macintosh-format file will contain \\r but not \\n . 同样,Macintosh格式的文件将包含\\r但不包含\\n

Simple search (Ctrl+F), Search Mode = Regular expression 简单搜索(Ctrl + F),搜索模式=正则表达式

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;" 例如,搜索return;$将发现“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 ) . [在Notepad ++ 5.8.5中测试]: 使用显式\\r\\n的正则表达式搜索不起作用(与Scintilla文档相反)
Neither does a search on an explicit (pasted) LF, or on the (invisible) EOL characters placed in the field when an EOL is selected. 当选择EOL时,也不会搜索显式(粘贴)LF或放置在字段中的(不可见)EOL字符。 Advanced search ( Ctrl + R ) without regexp 没有正则表达式的高级搜索( Ctrl + R

Ctrl + M will insert something that matches newlines. Ctrl + M将插入与换行符匹配的内容。 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. 例如,要删除双倍行距文件中的每个第二个换行符,请在搜索字符串框中输入两次Ctrl + M ,然后在替换字符串框中输入一次。

Advanced search ( Ctrl + R ) with Regexp. 使用Regexp进行高级搜索( Ctrl + R )。

Neither Ctrl + M , $ nor \\r\\n are matched. Ctrl + M$\\r\\n都不匹配。


The same wiki also mentions the Hex editor alternative : 同样的wiki还提到了Hex编辑器的替代方案

  • 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 . 选择一个新行并按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. 当您有“替换”对话框时,在背景上选择新的替换字符串,然后按Ctrl + C复制它以将其粘贴到“替换为文本”输入中。
  • Then Replace or Replace All as you wish. 然后根据需要更换或全部替换。

Note: the character selected for new line usually appears as 0a . 注意:为新行选择的字符通常显示为0a
It may have a different value if the file is in Windows Format. 如果文件是Windows格式,则它可能具有不同的值。 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 . 在这种情况下,您可以随时转到Edit -> EOL Conversion -> Convert to Unix Format ,更换后将其切换回来并Edit -> EOL Conversion -> Convert to Windows Format


#4楼

On the Replace dialog, you want to set the search mode to "Extended". 在“替换”对话框中,您要将搜索模式设置为“扩展”。 Normal or Regular Expression modes wont work. 正常或正则表达式模式不起作用。

Then just find "\\r\\n" (or just \\n for unix files or just \\r for mac format files), and set the replace to whatever you want. 然后只需找到“\\ r \\ n”(或只是\\ n用于unix文件或只用\\ r用于mac格式文件),并将替换设置为您想要的任何内容。


#5楼

I've not had much luck with \\r\\n regular expressions from the find/replace window. 我对查找/替换窗口中的\\ r \\ n正则表达式没有太多运气。

However, this works in Notepad++ v4.1.2: 但是,这适用于Notepad ++ v4.1.2:

  1. 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'.) (回车换行符应显示为单个着色的CRLF'字符'。)

  2. 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). 选择一个CRLF'字符'(将光标放在一个字符前面,按住SHIFT键,然后按一下RIGHT CURSOR键)。

  3. Copy the CRLF character to the clipboard. 将CRLF字符复制到剪贴板。

  4. Make sure that you don't have the find or find/replace dialog open. 确保您没有打开查找或查找/替换对话框。

  5. 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?) “查找内容”字段显示剪贴板的内容:在这种情况下,CRLF字符 - 显示为2个'字符'(可能是一个不可打印的字符?)

  6. Ensure that the 'Regular expression' option is OFF. 确保“正则表达式”选项为OFF。

Now you should be able to count, find, or replace as desired. 现在,您应该能够根据需要进行计数,查找或替换。


#6楼

使用高级搜索选项( Ctrl + R )并使用CRLF的键盘快捷键( Ctrl + M )插入回车符。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值