下一页</a>
<script>
(这里有换行什么的)
 </script>
<a href="
我怎么得到下一页
<a href="
的结果呢?谢谢,因为里面还有其他的javascript脚本所以不能都替换掉

解决方案 »

  1.   

    private string NoHTML(string Htmlstring)
    {
    //删除脚本
    Htmlstring = Regex.Replace(Htmlstring,@"<script[^>]*?>.*?</script>","",RegexOptions.IgnoreCase);
    //删除HTML
    Htmlstring = Regex.Replace(Htmlstring,@"<(.[^>]*)>","",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"([\r\n])[\s]+","",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"-->","",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"<!--.*","",RegexOptions.IgnoreCase);
    Htmlstring= System.Text.RegularExpressions.Regex.Replace(Htmlstring, "<[^>]*>", "");  string pattern = @"<[\s\S]*?>";
    Regex regex = new Regex(pattern);
    Htmlstring = regex.Replace(Htmlstring,"");

    Htmlstring = Regex.Replace(Htmlstring,@"&(quot|#34);","\"",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(amp|#38);","&",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(lt|#60);","<",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(gt|#62);",">",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(nbsp|#160);"," ",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(iexcl|#161);","\xa1",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(cent|#162);","\xa2",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(pound|#163);","\xa3",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring,@"&(copy|#169);","\xa9",RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);","",RegexOptions.IgnoreCase);
    Htmlstring=Regex.Replace(Htmlstring,@"<style(.[^>]*)>","",RegexOptions.IgnoreCase); Htmlstring.Replace("<","");
    Htmlstring.Replace(">","");
    Htmlstring.Replace("\r\n","");
    Htmlstring=Server.HtmlEncode(Htmlstring).Trim(); return Htmlstring;
    }
      

  2.   

    第一个
    str="....";
    Regex reg=new Regex(@"(?<=([\<]script[\>])[\s\S]+(?=([\<][\/]script[\>]))");
    MatchCollection m1=reg.Matches(str);for(int i=0;i<m1.Count;i++)
    {
      MessageBox.Show(m1[i].Value);//要取的在<script>与</script>之间的所有字符串
    }
    第二个
    Regex reg=new Regex(@"(?<=([\<][\s]+href[\s]*=[\s]*\")[\s\S]+(?=(\"))");