I have a list like following:
\u042f 12,197,051
\ube44\ud574 93,721,409
HUMAN 45,754,677
Overwatch 43,437,031 OVERWATE
Now I want to replace spaces with new lines in Comma-Separated number lines like following results:
\u042f
12,197,051
\ube44\ud574
93,721,409
HUMAN
45,754,677
Overwatch
43,437,031
OVERWATE
I tried following regex:
Find What: (^\h*)(.*?)(\h*,.*$)
Replace With: \1\2\n\3
But it not working good and provide me following results:
\u042f 12
,197,051
\ube44\ud574 93
,721,409
HUMAN 45
,754,677
Overwatch 43
,437,031 OVERWATE
Where is my regex problem?
If you want to replace leading spaces before comma separated numbers:
\h+(\d+(?:,\d+)+)(\h+)?
The pattern matches:
\h+
Match 1 or more horizontal whitespace characters(\d+(?:,\d+)+)
Capture group 1, match 1+ digits and repeat 1 or more times a comma and again 1+ digits(\h+)?
Optional group 2, match 1 or more horizontal whitespace charactersSee a regex demo
In the replacement a newline followed by the group 1 value, and if there is a group 2 value append another newline using a conditional:
\n$1(?{2}\n)