如何利用正则表达将以下字符串中的“01”、“32”……([0-9]{2})等以数组形式提取出来?(返回[01,32])字字字字字字字字<img src="http://domain.com/01.gif" class="ghiz">字字字字字字字<img src="http://domain.com/39.gif" class="ghiz">因为字符串可能比较长,要求不能够用循环、indexOf、split等方法。
谢谢。function fnFilter(str){
...}

解决方案 »

  1.   

    也不一定非要用循环不可
    <script>
    var str = '字字字字字字字字 <img src="http://domain.com/01.gif" class="ghiz">字字字字字字字 <img src="http://domain.com/39.gif" class="ghiz">';
    var re = /<img src=\"http:\/\/domain.com\/([\d]{2}).gif\" class=\"ghiz\">/gi;
    str = str.match(re).join(",").replace(re,"$1");
    alert(str);
    </script>
      

  2.   

    有道理,再split一下就可以满足lz的要求了.
      

  3.   


    function fnFilter(str){ 
    var regex=/\d{2}(?=\.gif["'])/igm;
    return str.match(regex).join(',');