Puppet Labs Puppet 2.7.x sp2Puppet Labs Puppet 2.6.x sp3Mozilla seamonkey 2.xMozilla Firefox 3.x分割为:
Puppet Labs Puppet 2.7.x sp2Puppet Labs Puppet 2.6.x sp3Mozilla seamonkey 2.xMozilla Firefox 3.x如何把类似的字符串分割,后面的版本号部分多变,可能有1.1,1.x,1.1 ps1, 1.1.1.1 emc,update1等多种形式,有没有适当的正则能把这件事请搞定?谢谢大家。正则

解决方案 »

  1.   


           string numstr = @"Puppet Labs Puppet 2.7.x sp2Puppet Labs Puppet 2.6.x sp3
    Puppet Labs Puppet 1.1.1.1 emc
    Mozilla seamonkey 2.xMozilla Firefox 3.x
    ";
                var mc = Regex.Split(numstr, @"(Puppet\s*Labs\s*Puppet[\s\S]*?(?=Puppet))|(Mozilla[\s\S]*?(?=Mozilla))");
                foreach (string mcnum in mc)
                {
                    Console.WriteLine(mcnum);
                }
      

  2.   

    foreach(Match m in Regex.Matches(yourstr,@"(?i).+?(\d+(\.\d+)?)+(\.x)?\s*((?:sp|emc|update)\d+)?"))
    {
       //m.Value即是你想要的
    }
      

  3.   


    大神谢谢了,给了我个思路,把您这正则研究透了我又能涨点知识~Chinajiyong~这位大牛也麻烦你了,谢谢