首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

帮忙看个正则解决办法

2012-04-05 
帮忙看个正则C# codestring strIp 0.0.0.00.255.255.255IANA保留地址CZ88.NET//刚接触正则,想分为3组

帮忙看个正则

C# code
            string strIp = "0.0.0.0         0.255.255.255   IANA保留地址  CZ88.NET";            //刚接触正则,想分为3组 写的有点问题 帮忙修改下 谢谢了            Regex reg = new Regex(@"(.+\s+)(.+\s+)(.+\s.+)");            Match mat = reg.Match(strIp);            if (mat.Success)            {                string str1 = mat.Groups[1].Value;                string str2 = mat.Groups[2].Value;                string str3 = mat.Groups[3].Value;            }


[解决办法]

C# code
static void Main(string[] args)            {                string strIp = "0.0.0.0         0.255.255.255   IANA保留地址  CZ88.NET";                Regex reg = new Regex(@"([^\s]+)\s*([^\s]+)\s*(.*)", RegexOptions.None);                Match mat = reg.Match(strIp);                if (mat.Success)                {                    string str1 = mat.Groups[1].Value;                    string str2 = mat.Groups[2].Value;                    string str3 = mat.Groups[3].Value;                    Console.WriteLine(str1);                    Console.WriteLine(str2);                    Console.WriteLine(str3);                }                            Console.ReadLine();                                                          }
[解决办法]
C# code
 string strIp = "0.0.0.0         0.255.255.255   IANA保留地址  CZ88.NET";            //刚接触正则,想分为3组 写的有点问题 帮忙修改下 谢谢了            Regex reg = new Regex(@"([\d.]*)\s*([\d.]*)\s*(.*)");            Match mat = reg.Match(strIp);            if (mat.Success)            {                string str1 = mat.Groups[1].Value;                string str2 = mat.Groups[2].Value;                string str3 = mat.Groups[3].Value;            } 

热点排行