Regex replace commas within parentheses C#

后端 未结 2 840
一向
一向 2021-01-27 03:52

I\'m having a hell of a time replacing commas only within parentheses for this string:

select distinct \\n(\'\'+rtrim(ent.custno)+\' - \'+rtrim(ent.com

2条回答
  •  囚心锁ツ
    2021-01-27 04:06

    Assuming your parentheses are paired and can be nested (balanced), and you need to replace all commas inside those balanced parentheses, you can use a regex to match those substrings and replace the commas with a match evaluator:

    cols = Regex.Replace(cols, @"\((?>[^()]|(?)\(|(?<-c>)\))*(?(c)(?!))\)", m => m.Value.Replace(",", ";"));
    

    See IDEONE demo

提交回复
热议问题