我想正常化一個字符串,然後繼續解析它。基本上刪除逗號前後的空格,如果兩個或多個逗號僅由空格分隔,則用逗號替換。正則表達式替換字符串
var r = new Regex(@"(\s*,+\s*)");
var query = r.Replace("my reg, is a disaster everytime , i,try ,it, yep, ,disaster.", ",");
輸出應爲:
my reg,is a disaster everytime,i,try,it,yep,disaster.
但其:
my reg,is a disaster everytime,i,try,it,yep,,disaster.
任何幫助理解