Search code examples
regexnotepad++

Combine/Join lines in Notepad++ based on separator


I have a text log file in the following format.

****************************************************************************************
line1
line2
line3
****************************************************************************************
line4
line5
line6
****************************************************************************************

Is there a way in Notepad++ to combine lines between the "*" separators so the data looks like below

****************************************************************************************
line1 line2 line3
****************************************************************************************
line4 line5 line6
****************************************************************************************

Thanks!


Solution

    • Ctrl+H
    • Find what: (?<!\*)\R(?!\*)
    • Replace with: # a space
    • SELECT Regular expression
    • Replace all

    Explanation:

    (?<!\*)         # negative lookbehind, make sure we haven't a * before
    \R              # any kind of linebreak
    (?!\*)          # negative lookahead, make sure we haven't * after
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here