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



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



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



  • 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


Log in to reply