Search code examples
tabsnotepad++line

Notepad++ Combine Specific Line with second line


I'm trying to combine every line that starts with "Text" with the second line:

Text 1  
    Line 1  
    Line 2  
    Line 3  
    Line 4
Text 2  
    Line 1  
    Line 2  
    Line 3
Text 3  
    Line 1  
    Line 2  
    Line 3  
    Line 4  
    Line 5  
    Line 6 
Text 4
    Line 1
    Line 2

And I'd like it to look like this.

Text 1      Line 1  
    Line 2  
    Line 3  
    Line 4
Text 2      Line 1  
    Line 2  
    Line 3
Text 3      Line 1  
    Line 2  
    Line 3  
    Line 4  
    Line 5  
    Line 6 
Text 4      Line 1
    Line 2

I have managed to combine them but the issue is that it removes the number, so it ends up like "Text Line 1" instead of "Text 1 Line 1". I want to keep the tab space as well.


Solution

    • Ctrl+H
    • Find what: (^Text.*)\R
    • Replace with: $1
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    (           # start group 1
    ^           # beginning of line
    Text        # literally Text
    .*          # 0 or more any character but newline
    )           # end group
    \R          # any kind of linebreak
    

    Replacement:

    $1          # content of group 1
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here