在行的最后一个分号后匹配逗号

在行的最后一个分号后匹配逗号

本文介绍了在行的最后一个分号后匹配逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV文件,其中的数据用分号隔开。在文件的最后一列中,我有一个用逗号分隔的数字列表。我不能用分号替换这些逗号,所以他们成为自己的列。

I have a CSV file that has data separated by semicolons. In the last column in the file, I have a list of numbers separated by a comma. I wan't to replace these commas with a semicolon so they become their own columns.

如何在每行的最后一个分号后匹配每个逗号?我不能用分号替换所有的逗号,因为文件中的其他一些列也包含逗号。

How do I match every comma after the last semicolon on each row? I can't just replace all commas with semicolons, because some other columns in the file contain commas too.

我想用Notepad ++替换它们。

I am trying to replace them in Notepad++.

189;1;data here, can contain commas;311,232,161,132,371

这应该成为

189;1;data here, can contain commas;311;232;161;132;371


推荐答案

这样的:

(?:;(?!.*;)|(?!^)\G)[^,]*\K,

替换为:

;

;(?!。*;)匹配最后的; 。它是一个; ,后面没有另一个;

;(?!.*;) matches the last ;. It's a ;, which is not followed by another ;.

(?!^)\G 用于在上一次比赛结束时匹配。

(?!^)\G is used to match at the end of a previous match.

(?:;(?!!*;)|(?!^)\G)意味着匹配最后 code>,或在上一场比赛的开始。

(?:;(?!.*;)|(?!^)\G) will mean either match the last ;, or at the start of the previous match.

[^,] * 非逗号,最后, \K 重置匹配,以便只匹配逗号。

[^,]* will match non commas, and lastly, \K resets the match to allow you match only the commas.

注意:并非所有的Notepad ++版本都支持 \G \K (我不记得哪一个是首先实现的,可能 \G )。

Note: Not all versions of Notepad++ support \G and \K (I don't remember exactly which one was implemented first though, probably \G).

你描述。解决方法可能是:

The above is more... what you described. A workaround could be this:

,(?!.*;)

匹配后面不跟; 前进。并替换为;

Match a , that is not followed by a ; ahead. And replace with ;.

这篇关于在行的最后一个分号后匹配逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 13:55