Delete line containg a word + previous line

  • Hello Guys ,

    I would like to get the code that deletes every line containing this /movie/ and the previous line ( / is included )

    Thanks in advance

  • @Anass-Chawki

    Ugh. You can’t give a better spec than that?

    How about a bit of sample data, even if you have to make it up?

  • Hello anass-chawki, and All,

    Quite easy with regexes ! So :

    • Open the Replace dialog ( Ctrl + H )

    • SEARCH (?-is)^.+\R.*/movie/.*\R


    • Tick the Wrap around option

    • Select the Regular expression search mode

    • Click once, on the Replace All button

    Et voilà !

    Remarks :

    • If you’re looking for the word movie, in any case ( for instance /MOVIE/ or /MoviE/ ), change the first part of the regex (?-is) with the syntax (?i-s)

    • On the other hand, if you want to delete the line containing /movie/ and a true empty line, above, use the syntax below :

    • SEARCH (?-is)^.*\R.*/movie/.*\R

    Notes :

    • First, the in-line modifiers (?-is) :

      • Forces the search to be processed in a non-insensitive way

      • Forces to regex engine to interpret any dot ( . ) as representing a single standard character, NOT EOL character(s)

    • Then, the part ^.+\R looks for a complete non-empty line, with its EOL characters

    • Finally, the part .*/movie/.*\R searches any range, even null, of standard chars .*, followed with the string /movie/, with that exact case, and finally followed with an other range, even null, of standard chars .* and ended with its EOL chars \R

    • This selection of complete two lines is, then, deleted, due to the Empty replacement zone

    Best Regards,


Log in to reply