Remove multiple commas at the end of lines using N

2020-04-17 04:39发布

I have a text below with data in a CSV file

2,3
4,5
6,7

When I save an open this in notepad++, it has extra commas like

2,3,,,,
4,5,,
6,7,,,,,

like you see, there are variable number of leading commas,

I tried a regex match using:

/,{2,}/ 

I have selected the regular expressions combo-box from the search mode in ctrl + H Replace box.

For some reason this is not working. What do I need to do to match multiple comma and not get rid of single comma?

Is there a better way to get this done in notepad++?

2条回答
迷人小祖宗
2楼-- · 2020-04-17 05:08
\d+(?:,\d+)?\K.*$

You can use this.Replace by empty string.This will work with data like 2,3,

See demo.

https://regex101.com/r/iS6jF6/9

查看更多
贪生不怕死
3楼-- · 2020-04-17 05:27

Regex:

,{2,}$

Replacement string:

empty string

This will replace two or more trailing commas with an empty string. To remove all the trailing commas then use ,+$ regex.

查看更多
登录 后发表回答