javascript如何使用replace替换?

<script>

        function replacer(word) {

          return 'hello';

        }

        var newString = 'abc[你好]de[他]fg'.replace(/^\[[^\u0000-\u00FF]{1,2}\]$/gi, replacer);

        alert(newString)//todo:为什么这里显示的不是hellohello,我想把[你好][他]替换成hello

    

    </script>


鸿蒙传说
浏览 525回答 1
1回答

largeQ

不要匹配开始^和匹配末尾$function replacer(word) {&nbsp; &nbsp; return 'hello';}var newString = 'abc[你好]de[他]fg'.replace(/\[[^\u0000-\u00FF]{1,2}\]/gi, replacer);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript