我想把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;
}
如:
<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;
}
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;
}
{
string Pattern = "(?si)" + Regex.Escape(strBinCode) + ".*?" + Regex.Escape(strEndCode);
return Regex.Replace(StrContent, Pattern, string.Empty);
}
但用了一段比较长的就不行了!3楼的方法可以!结贴!