比如string str="11 12 13;14 9 16;";
如何把其中的数字提取出来,其中的数字0<n<21,11 12 13属于一组14 9 16属于另一组,也就是用 ; 分开我把检查条件写出来了是: Regex re = new Regex(@"^(([1-9]|1[0-9]|2[0-1])[\s|;]*)+;$");但是我不知道如何提取出来?

解决方案 »

  1.   

    不知道lz是不是要这样提取?
      string str="11 12 13;14 9 16;";
                string[] str1 = new string[2];
                str1 = str.Split(';');
                for (int i = 0; i < str1.Length; i++)
                {
                    Console.WriteLine(str1[i]);
                }
      

  2.   

    ls 不行 一定要regex来提取
    ps 字符长度不定的 也就是说可能是 string str="11 12 13;14 9 16;15 16;18;"; 
      

  3.   

    看不懂楼主要做什么,如果无法描述清楚,就把你的结果列出来string str = "11 12 13;14 9 16;";
    MatchCollection mc = Regex.Matches(str, @"\d+");
    foreach (Match m in mc)
    {
        Console.WriteLine(m.Value);
    }
    Console.ReadLine();
      

  4.   

    ls
    比如:string str="11 12 13;14 9 16;15 16;18;21 19;"; 
    结果
    11 12 13
    14 9 16
    15 16
    18
    21 19
      

  5.   

    说实在的,这个真的没必要用正则来做,直接Split就可以做到string str = "11 12 13;14 9 16;15 16;18;21 19;";
    MatchCollection mc = Regex.Matches(str, @"(\d+\s*)+(?=;)");
    foreach (Match m in mc)
    {
        Console.WriteLine(m.Value);
    }
    Console.ReadLine();
      

  6.   

    = =!介个,弱弱滴说,我6楼给的是正则的string str = "11 12 13;14 9 16;15 16;18;21 19;";
    Regex re = new Regex(@"(\d+\s*)+(?=;)");
    MatchCollection mc = re.Matches(str);
    foreach (Match m in mc)
    {
        Console.WriteLine(m.Value);
    }
    Console.ReadLine();