How to Backspace New Line Characters in Notepad++

11,257

Solution 1

You can find/replace a line break by deleting the (non-print) characters usually its CRLF (cartridge return + line feed) depending on the OS/program that created the file's content. Notepad++ will display non-print characters if you turn on "show all characters". To find that in notepad++ you can use \r\n (using extended search mode or regular expression).

In scenario 1a you should replace/delete all line breaks followed by a pipe (\r\n|):

  • Find: \r\n|
  • Replace with: (leave empty)

This will change the following text:

dhdh
|jgfgf
hhgfh

to this text:

dhdhjgfgf
hhgfh

In scenario 1b you should replace all line breaks followed by a pipe (\r\n|) with a pipe (|):

  • Find: \r\n|
  • Replace with: |

This will change the following text:

dhdh
|jgfgf
hhgfh

to this text:

dhdh|jgfgf
hhgfh

In scenario 2a (from your question) you should replace/delete all line breaks (\r\n):

  • Find: \r\n
  • Replace with: (one space character)

This will change the following text:

dhdh
|jgfgf
hhgfh

to this text:

dhdh| jgfgf hhgfh

In scenario 2b (from your comments) you should replace/delete all line breaks (\r\n):

  • Find: \r\n
  • Replace with: (leave empty)

This will change the following text:

dhdh
|jgfgf
hhgfh

to this text:

dhdh|jgfgfhhgfh

Note:

Using RegEx instead of "Extended Search" you can use \R (note the upper case) instead of \r\n (see full RegEx-Guide), thanks to Toto for pointing that out!

Solution 2

  • Ctrl+H
  • Find what: \R(?=\|)
  • Replace with: LEAVE EMPTY
  • CHECK Wrap around
  • SELECT Regular expression
  • Replace all

Explanation:

\R          # any kind of linebreak (i.e. \r, \n, \r\n)
(?=\|)      # positive lookahead, make sure we have a pipe after

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Share:
11,257

Related videos on Youtube

Naveen K. Sanadhya
Author by

Naveen K. Sanadhya

Updated on September 18, 2022

Comments

  • Naveen K. Sanadhya
    Naveen K. Sanadhya over 1 year

    I have a file with the following format

    dhdh
    |jgfgf
    hhgfh
    

    I want to find the | (pipe) symbol in a new line and replace it with backspace

    For finding this, my regex is as below

    ^[|]{1}[a-zA-Z]
    

    It is working perfectly, but I am unable to replace it with backspace in end of previous line as below.

    dhdh|jgfgf
    hhgfh
    

    And the second case for text only

    ^[a-zA-Z]
    

    For this the desired result is

    dhdh|jgfgfhhgfh
    

    Please suggest me how can it be done?

    • Naveen K. Sanadhya
      Naveen K. Sanadhya about 4 years
      And For Second Scenario?
    • Albin
      Albin about 4 years
      not sure about the second scenario, could you give an example (before and after with the desired result)?
    • Naveen K. Sanadhya
      Naveen K. Sanadhya about 4 years
      Same Example As For PIpe Symbol, the difference is it Don't have prefix PIPE(|) symbol in new line
    • Albin
      Albin about 4 years
      please add a specific example into your question (before and the desired after) not just an explanation about it and not a general one with ^[a-zA-Z] otherwise I'm not sure if I understand it correctly
    • Naveen K. Sanadhya
      Naveen K. Sanadhya about 4 years
      Let Suppose I Have a Block with jgfgfNEW_LINEhhgfh, I Have to Replace it with jgfgfSPACE_WITHOUT_NEWLINEhhgfh EX: jgfgf hhgfh like this
    • Albin
      Albin about 4 years
      difficult to to say if I understand correctly through the comments (that's why you should add it to your question), but if I do you just need to replace the line break characters with a space. But you will need something to evaluate when not to replace the line break, other wise you will replace all of them.
  • Albin
    Albin about 4 years
    good answer, two comments: \r only replaces RF not LF! Although warp around is helpful it's not necessary (without warp around the search will stop at the end of the text file, with it will continue at the beginning).
  • Toto
    Toto about 4 years
    @Albin: I used \R (uppercase), it stands for any kind of linebreak as I said in my explanation. I use to always use wrap around because it makes the change global evan if your cursor is in the middle of the file.
  • Albin
    Albin about 4 years
    nice, didn't know about the uppercase option, that's helpful, thanks!