title: Delete all lines (not) matching a regex using Notepad++
body: <p>How to delete all lines matching or not matching a regex in Notepad++?</p>
  
  <p>In Vim, I'd do the following to delete all matching lines:</p>
  
  <pre><code>:g/regex/d
  </code></pre>
  
  <p>And to delete all non matching lines:</p>
  
  <pre><code>:!g/regex/d
  </code></pre>
  
  <p>I'm looking for these commands' equivalent in Notepad++.</p>
  
  <p>As also explained in "<a href="https://stackoverflow.com/questions/23472052/notepad-delete-all-lines-with-certain-text">Notepad++ - delete all lines with certain text</a>", I usually go for the approach of blanking the matching lines and deleting the blank lines afterwards. Is there a simpler way?</p>
  
  <hr>
  
  <p>As per <a href="https://stackoverflow.com/a/5185998/1698309">this answer</a>, versions of Notepad++ >= 6.0 support matching line breaks in regex, thus allowing to delete whole lines directly without creating blank lines first. The following pattern should remove all lines containing "foobar" when replaced with an empty string:</p>
  
  <pre><code>^.*foobar.*\r\n
  </code></pre>
  
  <p>Now, as discussed in "<a href="https://stackoverflow.com/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word">Regular expression to match a line that doesn&#39;t contain a word?</a>", negating regular expressions isn't exactly straightforward. Deleting lines in Notepad++ which do not contain "foobar" would require the following pattern:</p>
  
  <pre><code>^((?!foobar).)*\r\n
  </code></pre>
  
  <p>Because that's a quite complicated command to type just for removing lines which don't contain a word (or possibly more complex expression), I wonder if there is an easier solution.</p>