fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. // your code goes here
  9. string input = "红包(¥2000.00(红包零钱ID:1115)) ";
  10. input = input.Replace("(","(");
  11. input = input.Replace(")", ")"); //将括号统一换成半角的
  12. string pattern = @"\([^\(\)]*(((?<Open>\()[^\(\)]*)+((?<-Open>\))[^\(\)]*)+)*(?(Open)(?!))\)"; //使用递归平衡组匹配嵌套的括号
  13. string replacement = "###"; //替换成什么写在这里
  14. Regex rgx = new Regex(pattern);
  15. string result = rgx.Replace(input, replacement);
  16. Console.WriteLine(result);
  17. }
  18. }
Success #stdin #stdout 0.04s 19484KB
stdin
Standard input is empty
stdout
红包###