8

I use Notepad++ and I need to delete all lines starting with, say "abc".

Attention, I don't need to replace the line starting with "abc" with a empty line, but I need to completely delete these lines.

How do I proceed (using regex, I suppose)?

serhio
  • 28,010
  • 62
  • 221
  • 374
  • 1
    This may help you http://stackoverflow.com/questions/918158/how-to-delete-specific-lines-on-notepad – vmeln Mar 04 '13 at 13:36

5 Answers5

10

Try replace

^abc.*(\r?\n)?

with

nothing

The ^ indicates the start of a line.

The . means wild-card.

The .* means zero or more wild-cards.

x? means x is optional.

The \r?\n covers both \r\n (generally Windows) and \n (generally Unix), but must be optional to cover the last line.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
2

Search for this regular expression

^abc.*\r\n

Replace with nothing.

ellak
  • 2,531
  • 20
  • 26
0

Try the regex \nabc.* in "Find and Replace" --> "Replace"
Leave "Replace With" field empty.

EDIT : This won't work with first like (because '\n' means "new line")

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Neozaru
  • 1,109
  • 1
  • 10
  • 25
0

Searching a little bit more on regex in Notepad++ I discovered that the new line character is not \n as I expected (Windows), but the \n\r.

So, my regex replace expression should be:
Find: abc.*\r\n
Replace with: (nothing, empty field)

serhio
  • 28,010
  • 62
  • 221
  • 374
0

Press Ctrl+H to bring up the Replace window. Put

^abc.*(\r?\n)?

in the Find what and leave Replace with empty. Select Reqular expression and hit Replace All.

This reqular expression handles all the edge cases:

  • When the first line of the file starts with abc
  • When the last line of the file starts with abc and there is no new line at the end of the file.
Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72