var src = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}"
var re = /{([^{}]+)}/g;
var arr;
while ((arr = re.exec(src)) != null)
      alert(arr[1]);

解决方案 »

  1.   

    str = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}";
     reg = /\{[^(\{|\})]*\}/g
     arr = str.match(reg)
     alert(arr)
      

  2.   

    fokker(独孤龙) :你的结果是:
    {dfds34#$#},dfds34#$#  chenyang37(norika) :
    你的结果是:
    {dfds34#$#},{},{sdf23},{sd},{as},{sd} 
    我要的结果是:
    dfds34#$#,,sdf23,sd,as,sd
    这样一个数组集合。chenyang37的方法加上replace也可以,但我希望能用正则一次性把它求出。
      

  3.   

    ie5.0,fokker(独孤龙) 的结果是不停得alert“dfds34#$#}”
      

  4.   

    alert(("{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}").match(/([^{}]+|(?={}))/g))
      

  5.   

    var src = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}"
    var re = /\{([^\{\}]*)\}/g;
    result=src.match(re)
    alert(result.join().replace("{","").replace("}",""))
    -
    测试通过
      

  6.   

    不过我建议还是用/{([^{}]+)}/g进行match以后,再replace掉{}
    因为用上面这个式子的话,不能保证左右分别是{和}
      

  7.   

    var src = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}"
    var re = /\{([^\{\}]*)\}/g;
    result=src.match(re)
    alert(result.join().replace(/\{/g,"").replace(/\}/g,""))
    修正一下
      

  8.   

    walkingpoison(walkingpoison):你的方法在IE5下产生错误提示:“错误的数量词” bzscs(沙虫) :你还是用了replace进行二次加工的。
      

  9.   

    s="";
     str = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}";
     reg = /\{([^(\{|\})]*)(\})/g
     while((arr = reg.exec(str))!=null)
     s+=RegExp.$1+","
     alert(s)
      

  10.   

    Hello?
    试试这个:(?!{|})[^{}]*(?=\})或者这个
    [^{}][^{}]*(?=\})针对这个能成功,但是我暂时还想不出把前面的 { 替换成 [^{}] 或者 (?!{|}) 的原因;;我只是尝试了几次,发现是可以的…… 【原本我是想把前面的 { 替换成 (?={) 的,结果发现不行tmd..】附:俺做的一个测试工具 RegExpTest.html 
    --------------------------
    <script language="JavaScript" type="text/javascript">
    function doReplace ()
    {
    var source = sourceEditbox.value;
    var pattern = patternEditbox.value;
    var replacement = replacementEditbox.value;

    resultEditbox.value = source.replace (new RegExp(pattern, "g"), replacement);
    showRegExp ();
    }function doMatch ()
    {
    var source = sourceEditbox.value;
    var pattern = patternEditbox.value;

    resultEditbox.value = source.match (new RegExp(pattern, "g"));
    showRegExp ();
    }function showRegExp ()
    {
    var theText = "";
    theText += "RegExp.input=" + RegExp.input; /* $_ */
    theText += "\n";
    theText += "RegExp.lastMatch=" + RegExp.lastMatch; /* $& */
    theText += "\n";
    theText += "RegExp.lastParen=" + RegExp.lastParen; /* $+ */
    theText += "\n";
    theText += "RegExp.leftContext=" + RegExp.leftContext; /* $` */
    theText += "\n";
    theText += "RegExp.rightContext=" + RegExp.rightContext; /* $' */
    theText += "\n";
    theText += "RegExp.multiline=" + RegExp.multiline; /* $* */
    theText += "\n"; theText += "RegExp.$1=" + RegExp.$1;
    theText += "\n";
    theText += "RegExp.$2=" + RegExp.$2;
    theText += "\n";
    theText += "RegExp.$3=" + RegExp.$3;
    theText += "\n";
    theText += "RegExp.$4=" + RegExp.$4;
    theText += "\n";
    theText += "RegExp.$5=" + RegExp.$5;
    theText += "\n";
    theText += "RegExp.$6=" + RegExp.$6;
    theText += "\n";
    theText += "RegExp.$7=" + RegExp.$7;
    theText += "\n";
    theText += "RegExp.$8=" + RegExp.$8;
    theText += "\n";
    theText += "RegExp.$9=" + RegExp.$9;
    theText += "\n"; theRegExpProperties.innerText = theText;
    }
    </script>
    源字符串:<br>
    <textarea name="sourceEditbox" cols="80" rows="5" id="sourceEditbox">this is the source string to be operate...
    </textarea>
    <br>
    <br>
    <p>Pattern:<br></p>
    <input name="patternEditbox" type="text" id="patternEditbox" value="[ab]">
    <input name="replace" type="button" id="replace" value="替换" onClick="doReplace();">
    <input name="search" type="button" id="search" value="匹配" onClick="doMatch();">
    <br>
    <br>
    替换者:<br>
    <input name="replacementEditbox" type="text" id="replacementEditbox" value="/">
    <br>
    <br>
    <hr size="1" noshade>
    <br>
    替换结果:<br>
    <textarea name="resultEditbox" cols="80" rows="5" id="resultEditbox"></textarea>
    <div id="theRegExpProperties"></div>
      

  11.   

    不对啊,你这个根本就不执行啊,连null都不出现
      

  12.   

    LoveTide(一个月挣多少钱知足?) 果然妙着, 学习了!:var str = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}";
    alert(str.match(/[^{}][^{}]*(?=\})/g));
      

  13.   

    hrong(黄蓉 修炼【九阴真经】) :为什么有错误提示啊:“错误的数量词”我的IE5
      

  14.   

    下在这个应该可以了!
    var src = "{dfds34#$#}}}{}{{sdf23}{sd}{as}{sd}"
    var re = /[^{}][^{}]*(?=\})/g;  '(?=\})匹配}前的那部分,加上[^{}],就是前面的部份中                   '不包括{}
    var arr;
    while ((arr = re.exec(src)) != null)
          alert(arr[1]);
    'arr是一个集合,不能用alert一起打出来,要用循环写出来。所以提示数量词出错。