Community
    • Login

    How to remove text between two specified strings using Notepad++?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 12.2k 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.
    • PRATAP CHAVAP
      PRATAP CHAVA
      last edited by

      I have following lines of data

      File created by
      Status 23:
      Status 24:
      Status 25:
      Status 26:
      Status 27:
      Status 28:
      Status 29:
      Status 30:
      Status 31:
      Address
      Address 112: 044 0891.
      Address 113: 044 1502.
      Message log (200 messages)

      Message 1:
      Message 2:
      Message 2:
      Message 2:
      Message 2:
      Message 2:

      I wish to delete text between line 1(File created by ) and upto line “Message log (200 messages)”.

      Can someone please provide some suggestions and thoughts on this?

      Thank you very much.

      1 Reply Last reply Reply Quote 0
      • chcgC
        chcg
        last edited by chcg

        Via regex search&replace:

        Search term:

        (?s)^\t*File created by(.|\r\n)*?Message log
        

        Replace.with:

        Message log
        

        See also https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation
        and most probably there are more elegant searches possible.

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

          Hello, @pratap-chava and All,

          Regarding your needs, I think that a suitable regex S/R could be :

          SEARCH : (?s-i)^File created by.+?\RMessage log.+?$\R

          REPLACE Leave Empty

          Don’t forget to select the Regular expresion search mode and to tick the Wrap-around option

          Notes :

          • At beginning of the regex, the modifiers (?s-i) mean that :

            • The . dot regex character will match any single character ( Standard and EOL chars )

            • The search is performed in a sensitive way. If you prefer insensitive matches just change that part with (?si) !

          • Then the part File created by.+?\RMessage log looks, from beginning ( ^ ) of line, for any text, beginning with File created by and ending at the first expression Message log, preceded by a line-break ( \R )

          • Now, the final part .*?$\R tries to match a range of any character, ending at the nearest end of line ( $ ), and followed with a line-break ( \R )

          And, due to the empty replacement zone, all that block of text is, then, simply deleted !

          Cheers,

          guy038

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