How can I remove lines that begin with spaces in Notepad++?
- Ctrl+H
- Find what:
^\h+.*$\R?
- Replace with:
LEAVE EMPTY
- CHECK Wrap around
- CHECK Regular expression
- UNCHECK
. matches newline
- Replace all
Explanation:
^ # beginning of line
\h+ # 1 or more horizontal spaces
.* # 0 or more any character but newline
$ # end of line
\R? # optional linebreak
Screenshot (before):
Screenshot (after):
It's possible with a pure regex solution (see @Toto's answer) but perhaps the following solution, using bookmarks, is easier to grasp:
Open the Find dialog
Go to the Mark tab, search for
^
(that's 2 characters: a caret indicating 'the beginning of the line' and a space) and enable the 'Bookmark line' option. I assume your Search Mode is already set to Regular expression. Hit the 'Mark All' button.Delete all bookmarked lines (Search → Bookmarks → Remove bookmarked lines)
You can do this:
Hit Ctrl+H for find and replace.
Check mark regular expression.
Use the Regex
^\s+.*
in the Find box.Keep Replace box blank.
Click Replace All.