How can I remove lines that begin with spaces in Notepad++?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping
--
Chapters
00:00 How Can I Remove Lines That Begin With Spaces In Notepad++?
00:44 Accepted Answer Score 44
01:22 Answer 2 Score 18
02:02 Answer 3 Score 4
02:22 Answer 4 Score 4
02:59 Thank you
--
Full question
https://superuser.com/questions/1562674/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#notepad++ #regex
#avk47
ACCEPTED ANSWER
Score 44
- 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):
ANSWER 2
Score 18
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)
ANSWER 3
Score 4
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.
ANSWER 4
Score 4
Another solution which would seem to apply to your example would be to Select All
(Ctrl-A), then go to Edit
>Line Operations
>Sort Lines [pick one of them that best applies]
, and this will group all the lines beginning with spaces together in the sort, and you can then easily just select and delete them. This only works in this case because the lines you want to keep seem to be numerically sorted already. Obviously this might not apply if you don't want to change the sorting of the other lines.
Personally, I have Sort Lines Lexicographically Ascending
and Sort Lines as Integers Ascending
assigned to hotkeys because I use them so frequently for just this sort of thing.