首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

比较难的正则,大侠帮忙呀!谢过了解决方案

2011-12-28 
比较难的正则,大侠帮忙呀!谢过了({result: (A:{1,2,3}, B:{4,5,6}, C:{7,8,9}, total:26)})取其中的

比较难的正则,大侠帮忙呀!谢过了
({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} 

热点排行