Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding and replacing blank lines regex in Notepad++ [duplicate]

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**
like image 710
keith Fesed Avatar asked Mar 21 '11 17:03

keith Fesed


People also ask

How do I replace blank lines in notepad?

Open Notepad++ and the file you want to edit. In the file menu, click Search and then Replace. In the Replace box, in the Find what section, type ^\r\n (five characters: caret, backslash 'r', and backslash 'n'). Leave the Replace with section blank unless you want to replace a blank line with other text.

How do I find blank lines in notepad?

You can use \r\n to find blank lines from text files made within Windows, \r for Mac and \n for Linux.

How do you replace regex in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.


2 Answers

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

like image 79
Ivan Avatar answered Sep 27 '22 19:09

Ivan


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

like image 37
AdrianHHH Avatar answered Sep 27 '22 19:09

AdrianHHH