当前位置: 代码迷 >> JavaScript >> 正则水平比较菜,再正则,多谢
  详细解决方案

正则水平比较菜,再正则,多谢

热度:67   发布时间:2012-02-28 13:06:35.0
正则水平比较菜,再求一个正则,谢谢
aaaaaa <img   src= "images/[aa].gif "> fdsfdsa <img   src= "images/[bb].gif "> ccc

现在想把 <img   src= "images/[aa].gif "> 替换掉,只留[aa],如何做,谢谢

------解决方案--------------------
var b = 'aaaaaa <img src= "imaGes/[aa].gif "> fdsfdsa <img src= "images/[bb].gif "> ccc ';

alert(b.replace(/\ <img\ssrc\=\ "[a-z]+\/(\[.+?\])(.+?) "\> /ig, '$1 '));
------解决方案--------------------
<script>
var str= 'aaaaaa <img src= "images/[aa].gif "> fdsfdsa <img src= "images/[bb].gif "> ccc ';
re=/ <img.*(\[aa\]).*?> /ig;
str=str.replace(re, "[aa] ")
alert(str)
</script>


------解决方案--------------------
<script>
var str= 'aaaaaa <img src= "images/[aa].gif "> fdsfdsa <img src= "images/[bb].gif "> ccc ';
re=/ <img.*(\[aa\]).*?> /ig;
str=str.replace(re, "$1 ")
alert(str)
</script>
  相关解决方案