高分求解:如何使用JS 与正则表达式提取一段字符串中的 URL地址

来源:百度知道 编辑:UC知道 时间:2024/07/03 05:45:10
具体情况如下:
目前使用一个网页编辑小工具FCKeditor,需要将插入文中的图片及flash地址提取单独保存,如果在插入的时候保存则不能监听到后面的删除,所以只能在用户保存的时候处理 整段的HTML代码,提取其中的图片与flash的URL地址保存。。
不知道描述的清不清楚,如有疑问,请在下面跟~~在线等答案
如下:
<p><embed src="/WebSite2/Upload/flash/890.swf" type="application/x-shockwave-flash" play="true" loop="true" menu="true"></embed><img height="391" width="480" alt="" src="/WebSite2/Upload/image/hello.jpg" /><img alt="" src="http://localhost:3375/WebSite2/fckeditor/editor/images/smiley/20090515/115.gif" /></p>
截取其中的 图片和flash的 URL地址

把可能有的url地址发几个上来当例子

<textarea id="txt" cols=40 rows=10>
</textarea>
<input type="button" value="提取" onclick="flt()">
<script>
function flt()
{
var str=document.getElementById("txt").value;
var re=/(http(s)?\:\/\/)?(www\.)?(\w+\:\d+)?(\/\w+)+\.(swf|gif|jpg|bmp|jpeg)/gi;
var arr=str.match(re);
document.getElementById("txt").value="";
for(var i=0;i<arr.length;i++)
{
document.getElementById("txt").value+=arr[i]+"\n";
}
}
</script>