有这样的运算表达式:200+1-781 
正则表达式要取得的值是:200、+、1、-、781

解决方案 »

  1.   

    string[] array = Regex.Split("200+1-781", @"\b");
      

  2.   

     string str = @"200+1-781*2\3";
                Regex  re=new Regex(@"\d+|[-+\\\*]");
                MatchCollection mc = re.Matches(str);
                foreach(Match m in mc)
                    Console.WriteLine(m.Value);
      

  3.   

    string[] array = Regex.Split("200+1-781", @"(?!^|$)\b");using System;
    using System.Text.RegularExpressions;static class Program 

      static void Main() 
      {
        string[] array = Regex.Split("200+1-781", @"(?!^|$)\b");
        foreach (string s in array)
          Console.WriteLine('['+s+']');
      } 
      

  4.   


    string input = "123+5-6+89";
    string pattern = "(?<numder>\\d+)(?<op>[+\\-*/]?)";
    MatchCollection c = Regex.Matches(input, pattern);
    foreach (Match m in c)
    {
        MessageBox.Show(m.Groups["numder"].Value);
        MessageBox.Show(m.Groups["op"].Value);
    }