Obvs make sure you have the regex switch turned on in Find/Replace Inverse Search Search: ^(?!.*expression).* Find and replace everything except something Search: search(.*)anotherthing Replace: $1 Remove all blank lines Run this multiple times as needed Search: \n\n Replace: \n