Community
    • Login

    Delete line containg a word + previous line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 516 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Anass ChawkiA
      Anass Chawki
      last edited by

      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

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Anass Chawki
        last edited by

        @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?

        1 Reply Last reply Reply Quote 0
        • guy038G
          guy038
          last edited by

          Hello anass-chawki, and All,

          Quite easy with regexes ! So :

          • Open the Replace dialog ( Ctrl + H )

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

          • REPLACE Leave EMPTY

          • 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,

          guy038

          1 Reply Last reply Reply Quote 3
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors