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

超简单正则表达式求解...
比如字符串“baidu_{0}_{1}”怎么获取{}括号对的个数啊?这个字符串就是2个..因为我现在要根据这个参数个数预留文本框的个数..

------解决方案--------------------
Regex.Matches("baidu_{0}_{1}",@"\{[^}]+\}").Count
------解决方案--------------------
C# code

            string source = "baidu_{0}_{1}";
            Regex reg = new Regex(@"(?is){\d*}");
            MatchCollection mc = reg.Matches(source);
            MessageBox.Show(mc.Count.ToString());

------解决方案--------------------
C# code
            string str = "baidu_{0}_{1}";
            Regex rgx = new Regex(@"{\d+}");
            Console.WriteLine(rgx.Matches(str).Count);

------解决方案--------------------
Regex.Match(yourstr,"{[^{}]*?}").Count