Search code examples
regexnotepad++

Remove extra content from value lines


I have a list which following list is a part of my list:

PrtayStetaten2
155,198,293
NrteintenertdoDrtS
154,945,128
GartmertBertoy
119,227,195
PtylytayStytatn3
84,222,289
Xbttyryox36
X84,138,759
etghrth
345
hrhyjuj
0
tytyjhfdff
opop0
2018 Q3

Now i want to remove extra content from value lines only like following:

PrtayStetaten2
155,198,293
NrteintenertdoDrtS
154,945,128
GartmertBertoy
119,227,195
PtylytayStytatn3
84,222,289
Xbttyryox36
84,138,759
etghrth
345
hrhyjuj
0
tytyjhfdff
0
2018 Q3

I can't use following regex because it remove content from non-value lines like 2018 Q3 and PrtayStetaten2

find: ^.*?(?<!\d)(?<!\d,)(\d{1,3}(?:,\d{3})*)(?!,?\d).*

replace:  $1

how to solve this problem?


Solution

  • You could use this regex:

    ^(\D.*\R+)\D+
    

    which matches a complete line starting with a non-digit, followed by some non-digit characters at the beginning of the next line; and replace it with

    \1
    

    which will remove the non-digit characters at the start of the second line.

    Note:

    • ". matches newline" must not be checked
    • on unix machines you can replace \R+ with \n.

    Regex demo on regex101