Community
    • Login

    REGEX: Mark/Delete the 2 second line after some word

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 2.7k 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.
    • Vasile CarausV
      Vasile Caraus
      last edited by Vasile Caraus

      hello everyone. I need to mark/delete the 2 second line after some word. For exemple:

      1.line
      2.line
      3.bla bla bla WORD_1 bla bla
      4.line
      5.line
      6.line ETC

      So, I want to delete the line that contains WORD_1 and the next 2 lines (but without line 6). Can anyone help me?

      I try this regex, this will delete the line with WORD_1, but will not delete line 4 and 5. But will insert another line 4 instead delete.

      Search:
      ^.*WORD_1.*$
      Replace by:
      \n\n

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

        Hello, Vasile,

        Not difficult, indeed !

        The general regex S/R, which deletes ANY line, containing a SPECIFIC word, with generic name = WORD, along with the N lines, following this line, is :

        SEARCH (?-s)^.*WORD.*\R(.*\R){N}

        REPLACE EMPTY

        So, in your case, the search regex should be (?-s)^.*WORD_1.*\R(.*\R){2}


        In the same way, the general regex S/R, below, which would delete ANY line, containing the word WORD and the N lines located BEFORE this line, is :

        SEARCH (?-s)(.*\R){N}.*WORD.*\R

        REPLACE EMPTY


        Notes :

        • Due to the (?-s) modifier, the dot, ., stands for a single standard character, only

        • As usual, the \R syntax matches any kind of Line Break ( \r\n in Windows files, \n in Unix files or \r in old Mac files )

        • The part .*\R represents a complete line, even empty, with its EOL character(s)

        • So the syntax (.*\R){N}, where N is an integer, stands N complete lines

        Best Regards

        guy038

        1 Reply Last reply Reply Quote 0
        • Vasile CarausV
          Vasile Caraus
          last edited by

          well, guy38, nice present for me.

          thanks a lot !

          This is for you !

          https://www.youtube.com/watch?v=nPW5nfoIYf8

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