7

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
  • 27,402
  • 58
  • 213
  • 366
  • 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

9

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
  • 52,963
  • 14
  • 96
  • 130
2

Search for this regular expression

^abc.*\r\n

Replace with nothing.

ellak
  • 2,491
  • 18
  • 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
  • 52,963
  • 14
  • 96
  • 130
Neozaru
  • 1,059
  • 1
  • 10
  • 23
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
  • 27,402
  • 58
  • 213
  • 366
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,154
  • 3
  • 54
  • 67