Chaouki Anass
Chaouki Anass

Reputation: 997

NotePad++ : How to delete a line ( also the next line) that contains a specific word?

Let’s say for example we have this text and I want to delete every line that containts" delete me " and also the next line using NotePad++

a random text here1111
a random text here2222
a random text here delete me3333
a random text here 4444
delete me a random text here5555
a randomtext66666

So after applying what I want , the text is gonna be like this :

a random text here1111
a random text here2222

Upvotes: 0

Views: 3187

Answers (2)

Toto
Toto

Reputation: 91518

  • Ctrl+H
  • Find what: .*delete me.*\R.*(?:\R|$)
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

.*delete me.*   : literally "delete me" surrounded with 0 or more any character but newline
\R              : any kind of line break
.*              : 0 or more any character but newline
(?:             : start non capture group
  \R            : any kind of line break
 |              : OR
   $            : end of line
)               : end group

Result for given example:

a random text here1111
a random text here2222

Upvotes: 1

Arno C
Arno C

Reputation: 490

You can easily do this by making a regex matching your problem.

In your case such a regex would be:

(.)*(delete me)(.)*\n(.)*

This selects the line itself and the next one. Now it is only a matter of deleting the lines corresponding to said regex why is a possibility in notepad++. (see Regex: Remove lines containing)

If you want to tweak the regex feel free to toy around with it. Regxr allows very easy tweaking and testing of any regular expression.

Example on regxr.com

Upvotes: 0

Related Questions