高手们,能否给个正则表达式获取字符串的实例源码呢?网上大部分都是正则表达式的语法,以及一些验证字符串的方法。恳求达人们,给个关于获取的源代码给小弟学习一下。

解决方案 »

  1.   

           
            static void Main(string[] args)
            {
                Regex rx = new Regex(@"^\d*$");            String[] tests = {"12", "1s2", "34#2", "12 32","32.33"};            foreach (String test in tests)
                {
                    if (rx.IsMatch(test))
                    {
                        Console.WriteLine("{0} is a integer.", test);
                    }
                    else
                    {
                        Console.WriteLine("{0} is not a integer.", test);
                    }
                 }
              }
           }
      

  2.   


            static void Main(string[] args)
            {
                Regex rx = new Regex(@"\d+");            String str = "2342#fkdjf34#$%%    34dfd@343";            MatchCollection m = rx.Matches(str);            foreach (Match item in m)
                {
                    Console.WriteLine(item.Value);
                }
           }  
      

  3.   

    参考.NET正则基础——.NET正则类及方法应用