How can I remove lines that begin with spaces in Notepad++?

I need to remove lines that begin with spaces (the entire line, not just the spaces)

Here is an example of the file I'm working with:

41. 415607DB (AV-2011) 2007-06-23 (1D0703A2) (572D8DEC)
42. 415607DC (AV-2012) 2007-06-21 (4A5E805B) (73A29D08)
                       2009-11-18 (F830F241) (11F8A118)
43. 415607DD (AV-2013) 2007-07-12 (2D92F988) (2CB96AE4)
44. 415607DE (AV-2014) 2009-08-18 (A8E5F41B) (614BF7F6)
45. 415607DF (AV-2015) 2008-06-21 (8A3A88B8) (3B7CBB2D)
46. 415607E0 (AV-2016) 2011-03-29 (EF1BE81D) (2641EDA1)
                       2007-06-27 (7C19F25E) (1B17FCD8)
47. 415607E1 (AV-2017) 2007-11-21 (608D1D2F) (720B9353)
                       2007-11-29 (E55CEF10) (1BB2F934)
                       2007-06-21 (DD85E9F6) (2E07093A)
48. 415607E2 (AV-2018) 2009-07-07 (3D7B9FC0) (0F8AB402)

Here is the output I'm hoping to obtain:

41. 415607DB (AV-2011) 2007-06-23 (1D0703A2) (572D8DEC)
42. 415607DC (AV-2012) 2007-06-21 (4A5E805B) (73A29D08)
43. 415607DD (AV-2013) 2007-07-12 (2D92F988) (2CB96AE4)
44. 415607DE (AV-2014) 2009-08-18 (A8E5F41B) (614BF7F6)
45. 415607DF (AV-2015) 2008-06-21 (8A3A88B8) (3B7CBB2D)
46. 415607E0 (AV-2016) 2011-03-29 (EF1BE81D) (2641EDA1)
47. 415607E1 (AV-2017) 2007-11-21 (608D1D2F) (720B9353)
48. 415607E2 (AV-2018) 2009-07-07 (3D7B9FC0) (0F8AB402)

  • 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):

enter image description here

Screenshot (after):

enter image description here


It's possible with a pure regex solution (see @Toto's answer) but perhaps the following solution, using bookmarks, is easier to grasp:

  1. Open the Find dialog

  2. 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.

    enter image description here

  3. 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.


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.


I know this a Notepad question, but I can’t resist.

In vim, you could do

:global/^\s/delete

Which says to delete all lines starting with space.

You can script for automation like

printf '%s\n' 'global/^\s/delete' 'write' 'quit' | vim -es --clean file

Alternatively, with sed if you need to process a stream:

sed '/^[[:space:]]/d'