Search code examples
regexnotepad++

Copy multiple lines Notepad++


How can I duplicate 6 lines in notepad++?
For example I have:

a 01
a 02
a 03

And I want to make like this:

a 01
a 01
a 01
a 01
a 01
a 01
a 02
a 02
a 02
a 02
a 02
a 02
a 03
a 03
a 03
a 03
a 03
a 03

I just try with regex 3 times:

Find what : ^(.*)$
Replace with : $1\n$1

But i got 8 lines, not 6 lines


Solution

  • You get that result running that 3 times, because you duplicate all the lines 3 times going from 1->2->4->8 lines.

    If you want 6 lines, you can either match with ^.*$ (you don't need the capture group, $0 refers to the whole match) and write the full repetition of all the lines $0\n$0\n$0\n$0\n$0\n$0

    Or you can use the pattern ^(.*) with the replacement just 1 time to duplicate the lines

    Then replace per 2 lines as $0 now refers to 2 of the same consecutive lines due to the capture group and the backreference \1

    ^(.*)\R\1
    

    Replace with 3 times the whole match:

    $0\n$0\n$0
    

    enter image description here