Regex removing double/triple comma in string

前端 未结 5 878
一生所求
一生所求 2021-02-15 00:39

I need to parse a string so the result should output like that:

\"abc,def,ghi,klm,nop\"

But the string I am receiving could looks more like tha

5条回答
  •  春和景丽
    2021-02-15 01:23

    Search for ,,+ and replace all with ,.

    So in C# that could look like

    resultString = Regex.Replace(subjectString, ",,+", ",");
    

    ,,+ means "match all occurrences of two commas or more", so single commas won't be touched. This can also be written as ,{2,}.

提交回复
热议问题