正则表达式 {"20120225051":{"list":[],"result":{"red":["2","8","9","5","5"],"blue":[],"310":[],"extra":[]},"time_draw":"2012-02-25","time_exchange":"2012-04-24","formatSaleAmount":"0","formatPoolAmount":"0","open_time":"2012-02-25 14:31:00"},"20120225050":{"list":[],"result":{"red":["4","1","1","7","3"],"blue":[],"310":[],"extra":[]},"time_draw":"2012-02-25","time_exchange":"2012-04-24","formatSaleAmount":"0","formatPoolAmount":"0","open_time":"2012-02-25 14:21:00"}}
请问一下我杂样才能取得参数啊,如20120225051,28955,2012-02-25,2012-04-24,2012-02-25 14:31:00,
求高手了,我正则表达式不太会

解决方案 »

  1.   

    20120225051 ===> \d{11}
    28955       ===> \d{5}
    2012-02-25  ===> \d{4}[-]\d{2}[-]\d{2}2012-02-25 14:31:00 ===> \d{4}[-]\d{2}[-]\d{2}[\b]\d{2}[:]\d{2}[:]\d{2} 然后用"|"连起来,
    不就好了!
      

  2.   

    请参照如下代码:
    //把字符串写入文件data.txt,按行解析
    string[] input = File.ReadAllLines("data.txt");
    string pattern = @"(\d+).*(?<=red.*)(\d).*(\d).*(\d).*(\d).*(\d)""\].*(?<=time_draw"":"")([\d\-]+).*(?<=time_exchange"":"")([\d\-]+).*(?<=open_time"":"")([\d\- :]+)";Regex r = new Regex(pattern);MatchCollection mc = r.Matches(input[0]);
    foreach (Match match in mc)
    {
    for (int i = 0; i < match.Groups.Count; i++)
    {
    Console.WriteLine("第{0}组: {1}", i, match.Groups[i].Value);
    }
    }结果如下:
    第1组: 20120225051 
    第2组: 2
    第3组: 8
    第4组: 9
    第5组: 5
    第6组: 5
    第7组: 2012-02-25
    第8组: 2012-04-24
    第9组: 2012-02-25 14:31:00