• Login
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.
  • V
    Vasile Caraus
    last edited by Vasile Caraus Dec 29, 2016, 2:57 PM Dec 29, 2016, 2:57 PM

    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
    • G
      guy038
      last edited by guy038 Dec 29, 2016, 4:33 PM Dec 29, 2016, 4:00 PM

      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
      • V
        Vasile Caraus
        last edited by Dec 29, 2016, 6:58 PM

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