IE5.5以下用
<script>
var thestr="a1[b]a2[b]centerb2[/b]b1[/b]";
function qswhUBB(str){
var reg=/(\[b\])([^[]*)(\[\/b\])/gi,i=0;
while(str.match(reg))str=str.replace(reg,"<b>$2</b>");
return str;
}
alert(qswhUBB(thestr));
</script>
function replaceCallback(strFound,pos,strRaw)
{
var quots=[
{l:'(',r:")"},
{l:'[',r:"]"},
{l:'{',r:"}"}
];
var quot=quots[parseInt(strFound)%quots.length];
return quot.l+strFound+quot.r;
}
var str="9bJ47mwi8zchpq9N";
alert(str.replace(/[0-9]/g,replaceCallback));
alert("0123456789".replace(/[0-9]/g,replaceCallback));
function replaceCallback(strFound,pos,strRaw)
{
alert("在"+strRaw+"中\n第"+pos+"字符中[0,length)\n找到"+strFound);
}
var str="9bJ47mwi8zchpq9N";
str.replace(/[0-9]/g,replaceCallback);