Search code examples
regexnotepad++

Move regex areas to next line


I have a list like following:

WiytynXtP
54.76%
Witrn20t0t0
30.83%
Wrtinrt9t8
8.37%
Litrrtnurtrtx
3.17%
MtrtacrtS
2.60%
inrt9rtrt5/0.27%
Jul2004

Now I want to move all percentage values to next line using notepad++ regex.

I use following regex but not working for inrt9rtrt5/0.27% word

Find : (\d+\.\d+%)(\R)  
Replace : \1\2\2

I need something like following result:

WiytynXtP

54.76%
Witrn20t0t0

30.83%
Wrtinrt9t8

8.37%
Litrrtnurtrtx

3.17%
MtrtacrtS

2.60%
inrt9rtrt5/
0.27%
Jul2004

How to fix this?


Solution

  • You might use a match only without any capture groups:

    \d+\.\d+%\R
    

    The pattern matches:

    • \d+\.\d+% Match 1+ digits, a dot, 1+ digits and %
    • \R Match any newline unicode sequence

    In the replacement use a newline and the full match

    \n$0
    

    See a regex demo


    If you want to prepend the same newline that is matched by (\R) then you can use the capture group in the replacement, followed by the whole match:

    \d+\.\d+%(\R)
    

    And replace with

    $1$0
    

    Regex demo