![从逗号分隔的文件中删除最后一列](https://linux22.com/image/1505934/%E4%BB%8E%E9%80%97%E5%8F%B7%E5%88%86%E9%9A%94%E7%9A%84%E6%96%87%E4%BB%B6%E4%B8%AD%E5%88%A0%E9%99%A4%E6%9C%80%E5%90%8E%E4%B8%80%E5%88%97.png)
如何使用带有替换和查找的正则表达式从记事本++中的逗号分隔文件中删除最后一列?
这是我的文件:
2010-09-02,148.67,31.34,0,0,31.34
2010-09-03,149.52,31.24,0,0,31.24
...
我尝试在每行末尾找到此模式,基本上是最后一列或最后一个逗号后的所有内容,例如:
,31.34
,31.34
这是我目前所得到的,但它似乎选择了整行:
.*,\d+.\d+
我只想选择,31.34
并删除它,也就是用空内容替换它。
答案1
我测试了以下正则表达式,并且它有效:
搜索:(.+),.+?$
替换为:\1
正则表达式解释:
(.+),.+?$
( ) = this is a capture group. Its content will be \1, \2, \3 in order of appearance.
.+ = This selects everything greedy mode
, = until it finds the last comma.
(.+), = get everyting except the last , and store it in \1.
.+? = Get everything, non greedy.
$ = until we find the end of the string.
与问题中的正则表达式不同,只要所有内容都用.
分隔,这将对内容起作用。,