javascript 正则替换字符的新方法!

最近要对大量页面字符进行替换,百度半天,终于在村子dudu 发现一个好方法,代码如下:

 <script type="text/javascript">
  var s;
 var str='<img src="http://static.cnblogs.com/images/logo_small.gif" alt="" width="142" height="55" /><img src="http://static.cnblogs.com/images/logo_Big.gif" alt="" width="142" height="55" />';
 s=str.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
     return capture
});
  document.write(s);
</script>

最后输出的代码如下:

http://static.cnblogs.com/images/logo_small.gifhttp://static.cnblogs.com/images/logo_Big.gif 

由此看来,这时候输出的所有的字符,可以根据自己的需求split分组,进行调用,再次感谢村长

posted on 2013-01-22 17:17  ~紫鱼~  阅读(210)  评论(0编辑  收藏  举报