Sublime Forum

Delete all lines NOT containing broomstick

#1

I have a file with lots of lines. Some of them contain the word “broomstick” (not his real name). I’d like to delete all the lines that DO NOT contain broomstick.

Tried various combinations building off

^.broomstick.\n

which is exactly what I DON’T want to delete. I gather that the ^ at the beginning of a set will complement the set but couldn’t make it work.

Is there a way? Thanks!

0 Likes

#2

You can copy lines you don’t want to delete and paste them just in the same file or another tab, whatever.

1 Like

#3

excellent idea, thanks! I’ll see if I can make that happen. Not quite clear on how to grab the whole lines but I think I see the idea. :slight_smile:

1 Like

#4

A regex .*broomstick.* would match lines which contain broomstick.
If you need word boundary checking, you may use .*\bbroomstick\b.*.
And then you just have to click on the Find All button to select all matches.

2 Likes

#5

Ah think I’ve got it now, thanks.

1 Like

#6

You can also try the plugin FilterLines. It will create a new buffer (unsaved file) with all the lines containing some match-criterion, which could be broomstick

0 Likes