日期:2014-05-18  浏览次数:20815 次

比较难的正则,大侠帮忙呀!谢过了
({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,如何写正则表达式?

------解决方案--------------------
C# code
:\s*\(

------解决方案--------------------
C# code

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}