<!DOCTYPE html>
<html xmlns:html="http://www.w3.org/TR/WD-xsl" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns="http://schemas.microsoft.com/intellisense/ie5">
<head>
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="http://stylesheets/relatedlinks.css"/>
<link rel="stylesheet" type="text/css" href="http://includes/client/msgbox/msgbox.css"/>
<link rel="stylesheet" type="text/css" href="http://stylesheets/shared.css"/>
<SCRIPT LANGUAGE="javascript" defer="defer" src="http://includes/client/msgbox/modalbox.js"><!---->
</SCRIPT>
<script type="text/javascript">     
function DoWatchList()
{
          vtbl=document.getElementById('xxxx');
        }
        </script>
</head>
<body>
OK
</body>
</html>
求一正则表达式函数过滤html里面的<script type="text/javascript">   、<link rel="stylesheet".../>
最后的结果为<!DOCTYPE html>
<html xmlns:html="http://www.w3.org/TR/WD-xsl" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns="http://schemas.microsoft.com/intellisense/ie5">
<head></head>
<body>
OK
</body>
</html>
过滤html正则表达式过滤字符串过滤脚本样式

解决方案 »

  1.   

    Regex.Replace(input.ToString().Trim(), @"(<link(.|\n)*?\/>)", "", RegexOptions.IgnoreCase);
    Regex.Replace(input.ToString().Trim(), @"(<iframe(.|\n)*?<\/iframe>)", "", RegexOptions.IgnoreCase);
      

  2.   

    Regex.Replace(input.ToString().Trim(), @"(<script(.|\n)*?<\/script>)", "", RegexOptions.IgnoreCase);
      

  3.   

    组合一下也行Regex.Replace(内容, @"(<link(.|\n)*?\/>)|(<script(.|\n)*?<\/script>)", "", RegexOptions.IgnoreCase)
      

  4.   

    (?isx)
    <
     (?>
      (?'open'script[^>]*>)
      |(?'-open'</script)
      |(?:(?!</script).)*
     )*
    (?(open)(?!))
    >
    |<link\s*rel="stylesheet"[^>]*>