JavaScript 的replace正则问题 在线等
var aa= '<div id="{wo}" >{ni}</div>';
var reg1=/\{([a-z]+)\}/g;
var re1 = aa.replace(reg1, function($0,$1,$2){return(("["+$1+"]"));});
document.write(re1);
var bb= "Water boils at 212F 3F .2F 2.2F .2";
var reg2= /(\d+(\.\d*)?)F\b/g;
var re2 = bb.replace(reg2, function($0,$1,$2){return((($1-32)) + "C");});
document.write(re2);
把“{wo}”“{ni}”换成“[wo]”“[ni]”
上边就不行,下边就行,咋回事啊。。。。
------解决方案--------------------
你怎么知道它不行?
JScript code
var aa= '<div id="{wo}" >{ni}</div>';
var reg1=/\{([a-z]+)\}/g;
var re1 = aa.replace(reg1, function($0,$1,$2){return(("["+$1+"]"));});
document.write(re1);