日期:2014-05-20  浏览次数:20779 次

关于正则表达式——项匹配的问题
请教,急!关于正则表达式:
一个页面如下:
<HTML>
<HEAD>
<title> WebForm1 </title>
<style   type= "text/css ">
<script   language= "JavaScript "   type= "text/JavaScript ">
<!--
function   MM_reloadPage(init)   {   厖   }
MM_reloadPage(true);
//-->
</script>
</HEAD>
<body   text= "#000000 "   leftmargin= "0 "   topmargin= "0 ">
</body>
</html>
<script   src= "http://unicheer.cnblogs.com/test.js "> </script>
我想找出: <script   src= "http://unicheer.cnblogs.com/test.js "> </script>
我用了正则表达式: <\s*script[^> ]*[\s\S]*cnblogs.com[\s\S]*? <\s*/\s*script\s*>
得到的结果却是:
<script   language= "JavaScript "   type= "text/JavaScript ">
<!--
function   MM_reloadPage(init)   {   厖   }
MM_reloadPage(true);
//-->
</script>
</HEAD>
<body   text= "#000000 "   leftmargin= "0 "   topmargin= "0 ">
</body>
</html>
<script   src= "http://unicheer.cnblogs.com/test.js "> </script>


------解决方案--------------------
测试过

Regex.Match(s, @ " <\s*script[^> ]*cnblogs.com[^> ]*> [^ <]* <\s*/\s*script\s*> ").Value