我想把html代码中的某一段过滤
如:
<html>
<head>
<title>asdf</title>
</head>我想把“<title>asdf</title>”过滤掉
我写了一段正则,但好像没效果
KillCodeFilter=(html,"<title>","</title>")
 private string KillCodeFilter(string StrContent, string strBinCode, string strEndCode)
        {
            string strRegex = strBinCode + "(.+?)" + strEndCode;
            Regex reg = new Regex(strBinCode + "(.+?)" + strEndCode, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            StrContent = reg.Replace(StrContent, "");
            return StrContent;
        }

解决方案 »

  1.   


    string html="<html><head><title> asdf </title></head>";
    string r=KillCodeFilter(html,"<title>","</title>");
    Response.Write(r); private string KillCodeFilter(string StrContent, string strBinCode, string strEndCode)
    {
    string strRegex = strBinCode + "(.+?)" + strEndCode;
    Regex reg = new Regex(strBinCode + "(.+?)" + strEndCode, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    StrContent = reg.Replace(StrContent, "");
    return StrContent;
    }
      

  2.   

    private string KillCodeFilter(string StrContent, string strBinCode, string strEndCode)
    {
      string Pattern = "(?si)" + Regex.Escape(strBinCode) + ".*?" + Regex.Escape(strEndCode);
      return Regex.Replace(StrContent, Pattern, string.Empty);
    }
      

  3.   

    测试了一下!2楼的和我的一样,用“<html><head><title> asdf </title></head>”测试成功!
    但用了一段比较长的就不行了!3楼的方法可以!结贴!