JAVASCRIPT的REGEXP怪怪的,试试这个吧:var newstr="";
var str='asdfasd<img src="http://***/***/123.gif">asdfasdf<img src="http://***/***/456.gif">fasdfasdf<img src="http://***/***/789.gif">asdf';
var re = new RegExp('<img src=[^0-9]*([0-9]*)[.]gif">','g');var nLast = -1;
var arr;
while ((arr = re.exec(str)) != null)
{
  newstr +=str.substring(nLast,arr.index) + "[img " + RegExp.$1 + "]";
  nLast = arr.lastIndex;
}if (nLast != -1)
newstr += str.substring(nLast);//newstr:
//asdfasd[img 123]asdfasdf[img 456]fasdfasdf[img 789]asdf 

解决方案 »

  1.   

    谢谢你,我简化了一下:
    <script>
    msg = "<img src=\"http://asd.fas.df/asdf-asdf/1223.gif\">asdfasdf<img src=\"http://asdfasdf/asdfasdf/1223.gif\">asdfasdf<img src=\"http://asdfasdf/asdfasdf/1223.gif\">"; msg = msg.replace (/<img src=\"[^0-9]*([0-9]*)[.]gif\">/ig,"[faceicon $1]"); document.write (msg);
    </script>
      

  2.   

    "." normally means any character other than newline
    "[.]" makes it match a ".", of course, you can also do "\."