Finding and replacing blank lines regex in Notepad

2019-01-18 05:30发布

问题:

This question already has an answer here:

  • Removing empty lines in Notepad++ 20 answers

I'm using Notepad++ and basically I want to find all blank lines that don't contain text using Notepad++ regex. I know that there is a simpler way of doing this by using 'textfx,' but I'm looking for an expression to do this. Here is an example below with the symbols shown.

< ?php **CRLF**
**CRLF**                        *<- REMOVE THIS* 
$xxx = $_POST['xxx'];**CRLF**
$xxx = $_POST['xxx'];**CRLF**
$xxx = $_POST['xxx'];**CRLF**
**CRLF**                        *<- REMOVE THIS* 
**CRLF**                        *<- REMOVE THIS* 
if ($xxx)**CRLF**
{**CRLF**

回答1:

Not a regular expression, but Notepad++ 6.3.2 has a number of ways of removing blank lines without using a regular expression.

Menu => Edit => Line operations => Remove empty lines

Menu => Edit => Line operations => Remove empty lines (containing blank characters)

Menu => TextFx => TextFx Edit => Delete blank lines

Menu => TextFx => TextFx Edit => Delete surplus blank lines

The two TextFx methods only delete empty lines, but they can be preceded with either of:

Menu => Edit => Blank operations => Trim trailing spaces

Menu => TextFx => vTextFx Edit** => Trim trailing spaces



回答2:

I've only been able to do this by using the "Extended" search mode in the Replace dialog (not "Regular expression" mode).

The search term I use is \r\n\r\n, and I replace it with \r\n. You have to keep repeating this until there were no changes, if there can be even more newlines in a row.

I also wish there was a better RegEx engine in Notepad++ with the ability to do multi-line searches.



回答3:

I just did find ^\r\n and replace with nothing



回答4:

Its possible, but not directly.

In short, go to the search, use the regex ^$ to search, check "mark lines" (in the current version there is a seperate mark tab in the search dialogue) and click "Find all". It results in bookmarks for all those lines.

In the search menu there is a point "delete bookmarked lines" thats it.



回答5:

Without using TextFx I don't think you can. There's no way I know of to tell the Find and Replace in Notepad++ that you want to delete the line. You can find all those lines by searching for '^$' (minus the quotes) with Regular Expression turned on. But the best you can do is replace it with an empty string, not a delete.



回答6:

In Notepad v6.2.2 there is option called Extended(\t\n......)
and In replace box, provide \r\n it works fine