使用一个网页编辑小工具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地址

解决方案 »

  1.   


    <script type="text/javascript">
    <!--
    var str = 's<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>'; var reg = /src\s*=\s*("|')([^"]+?)\1/g; while((result = reg.exec(str)) != null){
    alert(result[2])
    }//-->
    </script>
      

  2.   


    s = "<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>"
    re = /src="([^"]+)"/ig;
    while((arr=re.exec(s))!=null){
      alert(arr[1])
    }
      

  3.   

    非常感谢上面二位哈~~
    还能不能麻烦二位一下呢
    我这想将图片与flash 分开匹配查找
    这样的正则表达式该怎么写呢?
      

  4.   


    s = "<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>"
    re = /src="([^"]+.swf)"/ig;
    while((arr=re.exec(s))!=null){
      alert(arr[1])
    }
    re = /src="([^"]+(.jpg|.gif|.jpeg|.png))"/ig;
    while((arr=re.exec(s))!=null){
      alert(arr[1])
    }