日期:2014-05-17  浏览次数:20816 次

长字符串,怎么只替换括号外部的逗号而不替换括号内部的逗号
怎么只替换括号外部的逗号不替换括号内部的逗号,

如把这个字符串的括号外的逗号替换成"HHH":a(12,as)b,213s,sdf(re,sdfsd(sd,323))
替换结果:a(12,as)bHHH213sHHHsdf(re,sdfsd(sd,323))

------解决方案--------------------
C# code
string str = "a(12,as)b,213s,sdf(re,sdfsd(sd,323))";

                str = Regex.Replace(str, @"(?<=\G[^(),]+?(\((?>[^()]+|\((?<Open>)|\)(?<-Open>))*(?(Open)(?!))\))?[^(),]*),", "HHH");//
                //a(12,as)bHHH213sHHHsdf(re,sdfsd(sd,323))