<script> function replacer(word) { return 'hello'; } var newString = 'abc[你好]de[他]fg'.replace(/^\[[^\u0000-\u00FF]{1,2}\]$/gi, replacer); alert(newString)//todo:为什么这里显示的不是hellohello,我想把[你好][他]替换成hello </script>
1 回答

largeQ
TA贡献2039条经验 获得超7个赞
不要匹配开始^和匹配末尾$
function replacer(word) {
return 'hello';
}
var newString = 'abc[你好]de[他]fg'.replace(/\[[^\u0000-\u00FF]{1,2}\]/gi, replacer);
添加回答
举报
0/150
提交
取消