求正则表达式过滤<script>、<link>
<!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".../>
最后的结果为
过滤html 正则表达式过滤 字符串过滤脚本样式
<!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>
[解决办法]
Regex.Replace(input.ToString().Trim(), @"(<link(.
[解决办法]
\n)*?\/>)", "", RegexOptions.IgnoreCase);
Regex.Replace(input.ToString().Trim(), @"(<iframe(.
[解决办法]
\n)*?<\/iframe>)", "", RegexOptions.IgnoreCase);
[解决办法]
Regex.Replace(input.ToString().Trim(), @"(<script(.
[解决办法]
\n)*?<\/script>)", "", RegexOptions.IgnoreCase);
[解决办法]
组合一下也行
Regex.Replace(内容, @"(<link(.
[解决办法]
\n)*?\/>)
[解决办法]
(<script(.
[解决办法]
\n)*?<\/script>)", "", RegexOptions.IgnoreCase)
[解决办法]
(?isx)
<
(?>
(?'open'script[^>]*>)
[解决办法]
(?'-open'</script)
[解决办法]
(?:(?!</script).)*
)*
(?(open)(?!))
>
[解决办法]
<link\s*rel="stylesheet"[^>]*>