日期:2014-05-17  浏览次数:21026 次

求一个正则
<iframe   src= "http://aaa.bbb.cc "> xxx </iframe>

<iframe   width= "0 "   src=http://aaa.bbb.cc   frameborder=0> </iframe>

<iframe   src=http://aaa.bbb.cc   frameborder=0>
这里有汉字
</iframe>

怎么用正则匹配   以   <iframe   开头,中间包含   http   ,以   </iframe>   结尾
要求能匹配上边三个

------解决方案--------------------
<script language= "JavaScript ">
var str1, str2, str3;
str1 = " <iframe src=\ "http://aaa.bbb.cc\ "> xxx </iframe> ";
str2 = " <iframe width=\ "0\ " src=http://aaa.bbb.cc frameborder=0> </iframe> ";
str3 = " <iframe src=http://aaa.bbb.cc frameborder=0> \n这里有汉字\n </iframe> ";

var re = / <iframe(?:\s+[^> \s]+)*\s+src=[ " ']?([^ ' "\s> ]*)[ " ']?(?:\s+[^> \s]+)*> ([^ <]*) <\/iframe> /ig;
re.exec(str1);
alert(RegExp.$1 + "\n-----\n " + RegExp.$2);
re.exec(str2);
alert(RegExp.$1 + "\n-----\n " + RegExp.$2);
re.exec(str3);
alert(RegExp.$1 + "\n-----\n " + RegExp.$2);

</script>
------解决方案--------------------
在UltraEdit里用的:

<iframe ^(?^)*http^(?^)* </iframe>

<iframe ^(?^)*http^(?^)*^(^p^)* </iframe>
------解决方案--------------------
<iframe(?:\s+[^> \s]+)*\s+src=[ " ']?(http[^ ' "\s> ]*)[ " ']?(?:\s+[^> \s]+)*> ([^ <]*) <\/iframe>