({result: ("A":{1,2,3}, "B":{4,5,6}, "C":{7,8,9}, total:26)})取其中的"A":{1,2,3}、"B":{4,5,6}、"C":{7,8,9}等这个group,如何写正则表达式?

解决方案 »

  1.   

    :\s*\(split结果,在用(?<=}),split
      

  2.   

    那么多的,号,你怎么个splite法呀?最好用正则来做
      

  3.   


    using System;using System.Text.RegularExpressions;public class Test
    {
        static void Main(string[] args)
        {
            string str = @"({result: (""A"":{1,2,3}, ""B"":{4,5,6}, ""C"":{7,8,9}, total:26)})";        MatchCollection mc = Regex.Matches(str, @"""[A-Z].*?}");
            int count = mc.Count;
            if (count > 0)
            {
                Console.WriteLine("存在数据");
                for (int i = 0; i < count; i++)
                {
                    Console.WriteLine(mc[i].Value);
                }
            }
            else
            {
                Console.WriteLine("什么都没有");
            }
            Console.ReadKey();
        }
    }results:
    存在数据
    "A":{1,2,3}
    "B":{4,5,6}
    "C":{7,8,9}