我想匹配所有的
<script type="text/javascript"><!--
width=200
</script>
<script type="text/javascript"
src="../main.js" >
</script>但不想匹配
<script type="text/javascript"><!--
width=100
</script>
<script type="text/javascript"
src="../main.js" >
</script>
<script type="text/javascript"><!--
width=200
</script>
<script type="text/javascript"
src="../main.js" >
</script>但不想匹配
<script type="text/javascript"><!--
width=100
</script>
<script type="text/javascript"
src="../main.js" >
</script>
MatchCollection mc = Regex.Matches(yourStr,@"(?is)<script type="text/javascript"><!--
width=200.+?</script>.+?</script>");
foreach(Match m in mc)
{
//m.Value;
}
foreach(Match m in mc)
{
//m.Value;
}
我想匹配所有的
<script type="text/javascript"><!--
google_ad_client = "pub-3381531532877741";
/* 728x90, 创建于 10-12-1 */
google_ad_slot = "7423315034";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="../pagead2.googlesyndication.com/pagead/show_ads.js" >
</script>但不匹配
<script type="text/javascript"><!--
google_ad_client = "pub-3381531532877741";
/* 120x600, sidebar_big */
google_ad_slot = "9995842720";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="../pagead2.googlesyndication.com/pagead/show_ads.js" >
</script>他们之间的区别是google_ad_width,所以刚才我简写了,我现在用
<script(.*\s*){10}</script>
能把两个都匹配到,但我只想匹配宽度google_ad_width=728的所有,注意有回车符哈
你想要做什么,用Jquery做不到吗?
foreach(Match m in mc)
{
//m.Value;
}
<script[^>]*>([\s\S]*google_ad_width = 728[\s\S]*)?</script>
/* 728x90, 创建于 10-12-1 */
google_ad_slot = "7423315034";
google_ad_width = 728;
google_ad_height = 90;这里的排列顺序会不会改变?
{
string yourStr = @"不好用,我上边的是省略了一部分代码,为了突出重点,现在看来起反作用了。
我想匹配所有的
<script type=""text/javascript""><!--
google_ad_client = ""pub-3381531532877741"";
/* 728x90, 创建于 10-12-1 */
google_ad_slot = ""7423315034"";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type=""text/javascript""
src=""../pagead2.googlesyndication.com/pagead/show_ads.js"" >
</script>但不匹配
<script type=""text/javascript""><!--
google_ad_client = ""pub-3381531532877741"";
/* 120x600, sidebar_big */
google_ad_slot = ""9995842720"";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type=""text/javascript""
src=""../pagead2.googlesyndication.com/pagead/show_ads.js"" >
</script>他们之间的区别是google_ad_width,所以刚才我简写了,我现在用
<script(.*\s*){10}</script>
能把两个都匹配到,但我只想匹配宽度google_ad_width=728的所有,注意有回车符哈";
MatchCollection mc = Regex.Matches(yourStr, @"(?is)<script.*?google_ad_width\s*=\s*728.*?</script>.*?</script>");
foreach (Match m in mc)
{
MessageBox.Show(m.Value);
}
}
完整例子,你自己试试把。
google_ad_client = ""pub-3381531532877741"";
/* 728x90, 创建于 10-12-1 */
google_ad_slot = ""7423315034"";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type=""text/javascript""
src=""../pagead2.googlesyndication.com/pagead/show_ads.js"" >
</script>
<script type=""text/javascript""><!--
google_ad_client = ""pub-3381531532877741"";
/* 120x600, sidebar_big */
google_ad_slot = ""9995842720"";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script[\s\S]*?google_ad_width\s*=\s*728[\s\S]*?</script>[\s\S]*?</script>