regex_str = "( )+";//替换 为空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ", RegexOptions.IgnoreCase);
regex_str = "<script type=\\s*[^>]*>[^<]*?</script>";//替换<script>内容</script>为空格
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "<[^<]*>";//替换Html标签为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "(\r\n)*";//替换\r\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "\n*";//替换\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "\t*";//替换\t为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "'";//替换'为’
tmpContent = Regex.Replace(tmpContent, regex_str, "’", RegexOptions.IgnoreCase); regex_str = " +";//替换若干个空格为一个空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ", RegexOptions.IgnoreCase);
tmpContent = Regex.Replace(tmpContent, regex_str, " ", RegexOptions.IgnoreCase);
regex_str = "<script type=\\s*[^>]*>[^<]*?</script>";//替换<script>内容</script>为空格
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "<[^<]*>";//替换Html标签为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "(\r\n)*";//替换\r\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "\n*";//替换\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "\t*";//替换\t为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase); regex_str = "'";//替换'为’
tmpContent = Regex.Replace(tmpContent, regex_str, "’", RegexOptions.IgnoreCase); regex_str = " +";//替换若干个空格为一个空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ", RegexOptions.IgnoreCase);
Regex regex = new Regex(@"##");bodyStr = regex.Replace(bodyStr, temp =>
{
string key = temp.Value;
if (dic.ContainsKey(key))
return dic[key];
else
return temp.Value;
}, 99999);dic为字典,bodystr为网页源码
regex_str = "(?i) ";//替换 为空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ");//regex_str="<script type=\\s*[^>]*>[^<]*?</script>";//替换<script>内容</script>为空格
regex_str = "(?is)<script[^>]*>.*?</script>";//替换<script>内容</script>为空格
tmpContent = Regex.Replace(tmpContent, regex_str, "");//regex_str = "<[^<]*>";//替换Html标签为空
regex_str = "<[^<>]*>";//替换Html标签为空
tmpContent = Regex.Replace(tmpContent, regex_str, "");//regex_str = "(\r\n)*";//替换\r\n为空
regex_str = @"[\r\n]*";//替换\r\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase);//regex_str = "\n*";//替换\n为空
regex_str = @"\n*";//替换\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase);//可以这样
regex_str = "\t*";//替换\t为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase);//可以
regex_str = "'";//替换'为’
tmpContent = Regex.Replace(tmpContent, regex_str, "’", RegexOptions.IgnoreCase);//可以
regex_str = " +";//替换若干个空格为一个空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ", RegexOptions.IgnoreCase);其实你这些可以整合写成一个正则的。
regex_str = "(?i) ";//替换 为空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ");//regex_str="<script type=\\s*[^>]*>[^<]*?</script>";//替换<script>内容</script>为空格
regex_str = "(?is)<script[^>]*>.*?</script>";//替换<script>内容</script>为空格
tmpContent = Regex.Replace(tmpContent, regex_str, "");//regex_str = "<[^<]*>";//替换Html标签为空
regex_str = "<[^<>]*>";//替换Html标签为空
tmpContent = Regex.Replace(tmpContent, regex_str, "");//regex_str = "(\r\n)*";//替换\r\n为空
regex_str = @"[\r\n]*";//替换\r\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase);//regex_str = "\n*";//替换\n为空
regex_str = @"\n*";//替换\n为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase);//可以这样
regex_str = "\t*";//替换\t为空
tmpContent = Regex.Replace(tmpContent, regex_str, "", RegexOptions.IgnoreCase);//可以
regex_str = "'";//替换'为’
tmpContent = Regex.Replace(tmpContent, regex_str, "’", RegexOptions.IgnoreCase);//可以
regex_str = " +";//替换若干个空格为一个空格
tmpContent = Regex.Replace(tmpContent, regex_str, " ", RegexOptions.IgnoreCase);其实你这些可以整合写成一个正则的。
Regex reg = new Regex(@"(?is)(?:( |<script[^>]*>.*?</script>| +)|(<[^<>]*>|[\r\n\t]*)|('))");
string result = reg.Replace(s, delegate(Match m)
{
if (m.Groups[1].Success) return " ";
else if (m.Groups[2].Success) return "";
else if (m.Groups[3].Success) return "’";
else return "";
});