Blocco note ++ Elimina righe con Trova e sostituisci


12

Qualcuno sa come eliminare una riga usando Trova e sostituisci in Notepad ++?

Nella mia query Trova trova le linee giuste a posto: ^. pPrev. $ Nel campo Sostituisci, lo lascio vuoto pensando che la riga debba essere eliminata (ovvero sostituita con nulla), ma i caratteri di nuova riga e di fine riga rimangono.

Risposte:


11

Utilizzare l'impostazione "Esteso" nella finestra Sostituisci (non "Espressione regolare": Sono sicuro che esiste un modo per farlo con l'espressione regolare, ma l'uso di "Esteso" funziona correttamente).
Immettere " .pPrev.\r\n" nel campo "Trova cosa" e lasciare vuoto il campo "Sostituisci cosa". Ciò includerà i caratteri \ r \ n nella corrispondenza ed eliminerà l'intera riga.


1
Does not work anymore in later Notepad++ versions (5.9.2 UNICODE tested)
dtech

It seems like they keep pulling good features from Notepad++. First, the FunctionList plugin and now this. :(
Jim Fell

still working. If not, delete \n first and then delete \r
user4951

I came here looking for info on how to remove line breaks and \r\n worked for me like a charm. Thanks!
mabho

2

Using Regular expression: find \xd\xa and replace what you want

if want to delete line breakes , leave the replace form blank.


This worked for me where all other answers (pertaining to Notepad++) did not. I'm using v7.5.1
id.ot

1

You can actually select the newline by moving your cursor from the end of one line to the beginning of the next:

first line(from here)
(to here)decond line
third line

Then press ctrl+h while the new line is selected, and replace with nothing. This will delete all the newlines.


0

The general principle whichever editor you're using is that you need to include the new line characters (\r\n assuming Windows line endings) in your search so that they will be included in the replacement and thus removed.

In Notepad++ this is made a bit more confusing by the 2 different search and replace commands. See this Wiki page for details: Replacing Newlines in Notepad++

I only had an old version of Notepad++ to hand so had to use Extended Search (accessed via ^R), making sure Regular Expr was unticked and using ^M to insert the new line character into the Find field. However if you make sure you're using Notepad++ 4.9 or later you should be able to use \r and \n in the regexp mode.


I'm not able to use \r or \n in RegEx mode (version 5.8.6). They only work in Extended mode for me.
Justin

0

Not sure about Notepad++, but you can always do it with gVim. The command is like this:

%g/^.pPrev.$/d

You can download gVim here if you don't have it already.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.