有一些数据中包含很多像[10] [1,1] [11] [12] [13] 这样的数据....
现在要求先将这些数据全部找到,然后将他们依次提取出来放在另一个变量里面...这个怎么做? 查找我知道正则写可以...但是怎么将这些数据“剪切”式的提取出来哦?

解决方案 »

  1.   

    MatchCollection mc = Regex.Match(yourStr,@"\[[\d,]+\]");
    foreach(Match m in mc)
    {
        m.Value;//就是你要的
    }
      

  2.   


    List<string> l = new List<string>();
    MatchCollection mc = Regex.Match(yourStr,@"\[[\d,]+\]");
    foreach(Match m in mc)
    {
        string strChar = m.Value.ToString().Replace("[","").Replace("]","");
        string[] str  = strChar.Spilt(",");
        Foreach(string s in str)
        {
          l.Add(s);
        }}这样就的到10 1 1 11 12 13
      

  3.   

    不要[]的话直接
    MatchCollection mc = Regex.Match(yourStr,@"\[([\d,]+)\]");
    foreach(Match m in mc)
    {
        m.Groups[1].Value;//就是你要的
    }