俺只有这种笨方法:用(/d) 或/d+ 获得所有数字的匹配,再把所有匹配项连起来。
用[a-zA-Z]+ 获得所有字母匹配,同上。

解决方案 »

  1.   

    Regex r;
    Match m;
    string pattern;string chars = "";
    string num = "";pattern = @"(?<Characters>[a-zA-Z]+)|(?<Numbers>\d+)";
    r = new Regex( pattern );while ( m.Success )
    {
      chars += m.Groups[ "Characters" ].Value;
      num   += m.Groups[ "Numbers" ].Value;
    }
      

  2.   

    给你一个分组匹配的例子:(学习了别人的,可能对你有用! ^_^)string text = "abracadabra1abracadabra2abracadabra3"; 
       
        string pat = @" 
       
          ( # 第一个组的开始 
       
           abra # 匹配字符串abra 
       
           ( # 第二个组的开始 
       
           cad # 匹配字符串cad 
       
           )? # 第二个组结束(可选) 
       
          ) # 第一个组结束 
       
          + # 匹配一次或多次 
       
          "; 
       
        //利用x修饰符忽略注释 
       
        Regex r = new Regex(pat, "x"); 
       
        //获得组号码的清单 
       
        int[] gnums = r.GetGroupNumbers(); 
       
        //首次匹配 
       
        Match m = r.Match(text); 
       
        while (m.Success) 
       
         { 
       
        //从组1开始 
       
         for (int i = 1; i < gnums.Length; i++) 
       
          { 
       
          Group g = m.Group(gnums[i]); 
       
        //获得这次匹配的组 
       
          Console.WriteLine("Group"+gnums[i]+"=["+g.ToString()+"]"); 
       
        //计算这个组的起始位置和长度 
       
          CaptureCollection cc = g.Captures; 
       
          for (int j = 0; j < cc.Count; j++) 
       
           { 
       
           Capture c = cc[j]; 
       
           Console.WriteLine(" Capture" + j + "=["+c.ToString() 
       
             + "] Index=" + c.Index + " Length=" + c.Length); 
       
           } 
       
          } 
       
        //下一个匹配 
       
         m = m.NextMatch(); 
       
         }
      

  3.   

    LineString=sr.ReadLine()
    string [] Split =LineString.Split(new char[] {' '});
    Replace("'","")
      

  4.   

    private Boolean IsNumeric(string strVal)  //用正则表达式来判断TextBox中的数据是不是数字
    {  
    System.Text.RegularExpressions.Regex reg1 = new    System.Text.RegularExpressions.Regex("-?([0]|([1-9]+\\d{0,}?))(.[\\d]+)?$");  
      return reg1.IsMatch(strVal); 
    }  
    用这个方法一个字符一个字符的传入。
    如果是数字返回True
    if(IsNumeric(“3”))
    {是数字}