C#正则只取一个值

 
 
 
 
 
 
        private void button2_Click(object sender, EventArgs e)
        {
            string text2 = textBox1.Text;   //获取 textBox1 的文字
            string strTest1 = "Name\">[^<\\s]+";  //匹配系统名称
            string strTest2 = "Newest\">[^<\\s]+"; //匹配最新版本号
            string strTest3 = "href=\"[^\\s\"]+";   //匹配下载链接
            string strTest4 = "Current\">[^<\\s]+";   //匹配当前使用版本号
            string strTest5 = "Date\">[^<.]+";   //匹配到期日期
            string strTest6 = "Return\">[^<.]+";   //匹配注册返回值
                                                    
            
            MatchCollection mc;    //定义MC
            string[] results = new string[10];  //定义一个数组
            int[] matchpost = new int[10];
            Regex r = new Regex(strTest2);   //创建一个Regex对象
            mc = r.Matches(text2); //要查找的字符串
            textBox2.Text = mc[mc.Count - 1].Value;   //这样就可以取出最大标的值
            //for(int i=0; i< mc.Count; i++)          //下面可以输出所有的值
            //{
            //    results[i] = mc[i].Value;   //将查找到的字符串添加到数组
            //    matchpost[i] = mc[i].Index;  //记录查找到的位置
            //    textBox2.Text = textBox2.Text + mc[i].Value;
           // }

        }


猜你喜欢

转载自blog.csdn.net/heyics/article/details/80372488