热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在记事本+regex中匹配(并删除)LF字符-Match(anddelete)LFcharacterinNotepad++regex

InNotepadd++the\r\nregexwillfindalltheCRLFcombinations.ButIhavesomelineswhichendju

In Notepadd++ the \r\n regex will find all the CRLF combinations. But I have some lines which end just with LFs. First of all, what is that that? Next, how can I match and delete just that? Neither \r or \n works.

在Notepadd++ \r\n regex将找到所有CRLF组合。但是我有一些行,它的末尾是LFs。首先,那是什么?接下来,如何匹配和删除它呢?\r和\n都不管用。

3 个解决方案

#1


24  

LF stands for 'Line Feed'

LF代表“换行”

You can read some more on this answer on serverfault.se:

你可以在服务器故障上阅读更多关于这个答案的信息。

CR LF means "Carriage Return, Line Feed" - it's a DOS hangover from the olden days from when some devices required a Carriage Return, and some devices required a Line Feed to get a new line, so Microsoft decided to just make a new-line have both characters, so that they would output correctly on all devices.

CR低频意味着“回车,换行”——这是一个DOS宿醉从古代一些设备需要回车时,和一些设备需要换行得到一个新行,所以微软决定让一个新行字符,都使他们将在所有设备输出正确。

Windows programs expect their newline format in CRLF (\r\n). *nix expect just LF data (\n). If you open a Unix text document in Notepad on windows, you'll notice that all of the line breaks dissapear and the entire document is on one line. That's because Notepad expects CRLF data, and the Unix document doesn't have the \r character.

Windows程序在CRLF (\r\n)中期望他们的换行格式。*nix只希望得到LF数据(\n)。如果在windows上的记事本中打开一个Unix文本文档,您将注意到所有的行都中断了,整个文档都在一行上。这是因为Notepad需要CRLF数据,而Unix文档没有\r字符。

There are applications that will convert this for you on a standard *nix distro (dos2unix and unix2dos)

有一些应用程序可以在标准的*nix发行版(dos2unix和unix2dos)上为您转换此内容。

For those wondering, a carriage return and a line feed differ from back in Typewriter days, when a carriage return and a line feed were two different things. One would take you to the beginning of the line (Carriage Return) and a one would move you one row lower, but in the same horizontal location (Line Feed)

对于那些想知道的人来说,回车和换行与打字机时代的回车和换行是不同的。一个人会带你到线路的开头(回车),一个人会把你移动到一个低的位置,但是在相同的水平位置(换行)

Thus, you should be able to replace it with \n.

因此,您应该能够用\n替换它。

enter image description here

enter image description here

#2


11  

Using common sense I would suggest following approach:

根据常识,我建议采用以下方法:

  1. Replace all the CRLFs with some special string (that you are sure is not present in file), say "fuuuuuu!!!".
  2. 用一些特殊的字符串替换所有的CRLFs(您肯定没有出现在文件中),说“fuuuuuu!!!”
  3. Replace LFs with empty string.
  4. 用空字符串替换LFs。
  5. Replace all the special strings ("fuuuuuu!!!") back with CRLF.
  6. 用CRLF替换所有特殊的字符串(“fuuuu !!!”)。

And you are done.

和你做。

#3


1  

Set the encoding to ANSI.

将编码设置为ANSI。

Then \n will see only "LF"

然后\n只会看到“LF”


推荐阅读
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有