• Login
Community
  • Login

Delete line containg a word + previous line

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 3 Posters 520 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.
  • A
    Anass Chawki
    last edited by Jun 21, 2019, 11:01 PM

    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

    A 1 Reply Last reply Jun 22, 2019, 12:03 AM Reply Quote 0
    • A
      Alan Kilborn @Anass Chawki
      last edited by Jun 22, 2019, 12:03 AM

      @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
      • G
        guy038
        last edited by Jun 22, 2019, 12:12 AM

        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
        1 out of 3
        • First post
          1/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors