正则请大家帮个忙,多谢
正则求助:请大家帮个忙,谢谢
Puppet Labs Puppet 2.7.x sp2Puppet Labs Puppet 2.6.x sp3
Mozilla seamonkey 2.xMozilla Firefox 3.x
分割为:
Puppet Labs Puppet 2.7.x sp2
Puppet Labs Puppet 2.6.x sp3
Mozilla seamonkey 2.x
Mozilla Firefox 3.x
如何把类似的字符串分割,后面的版本号部分多变,可能有1.1,1.x,1.1 ps1, 1.1.1.1 emc,update1等多种形式,有没有适当的正则能把这件事请搞定?
谢谢大家。
------解决方案--------------------
------解决方案--------------------
Puppet Labs Puppet 2.7.x sp2Puppet Labs Puppet 2.6.x sp3
Mozilla seamonkey 2.xMozilla Firefox 3.x
分割为:
Puppet Labs Puppet 2.7.x sp2
Puppet Labs Puppet 2.6.x sp3
Mozilla seamonkey 2.x
Mozilla Firefox 3.x
如何把类似的字符串分割,后面的版本号部分多变,可能有1.1,1.x,1.1 ps1, 1.1.1.1 emc,update1等多种形式,有没有适当的正则能把这件事请搞定?
谢谢大家。
正则
------解决方案--------------------
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);
}
------解决方案--------------------
foreach(Match m in Regex.Matches(yourstr,@"(?i).+?(\d+(\.\d+)?)+(\.x)?\s*((?:sp
------解决方案--------------------
emc
------解决方案--------------------
update)\d+)?"))
{
//m.Value即是你想要的
}