Match (and delete) LF character in Notepad++ regex

后端 未结 3 1910
攒了一身酷
攒了一身酷 2020-12-25 12:56

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

相关标签:
3条回答
  • 2020-12-25 13:26

    Set the encoding to ANSI.

    Then \n will see only "LF"

    0 讨论(0)
  • 2020-12-25 13:40

    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. Replace LFs with empty string.
    3. Replace all the special strings ("fuuuuuu!!!") back with CRLF.

    And you are done.

    0 讨论(0)
  • 2020-12-25 13:43

    LF stands for 'Line Feed'

    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.

    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.

    There are applications that will convert this for you on a standard *nix distro (dos2unix and 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.

    enter image description here

    enter image description here

    0 讨论(0)
提交回复
热议问题