求教:在文本框中输入一组同学姓名(姓名之间用空格分开),
      创建适当的正则表达式,将所有姓杨的同学姓名
      在文本框下方的label控件中输出。

解决方案 »

  1.   

    //匹配
            string pattern = @"<[^>]>";
            string html = "abc<a href='login.aspx'>登陆</a>def";
            System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(html, pattern);
            if (m.Success)
            {
                Response.Write( m.Value);
                //m.NextMatch();
            }
            //替换
            Response.Write(System.Text.RegularExpressions.Regex.Replace(html, pattern, "这是替换后的内容"));
      

  2.   

    不好意思上面正则写错了,下面给你改过的
    //匹配
            string pattern = @"<[^>]*>";
            string html = "abc<a href='login.aspx'>登陆</a>def<p>789</p>";
            System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(html, pattern);
            while (m.Success)
            {
                Response.Write( m.Value);
                m = m.NextMatch();
            }
            //替换
            Response.Write(System.Text.RegularExpressions.Regex.Replace(html, pattern, "这是替换后的内容"));