var text=\'Hello world, Hello world\'; var b= text.replace(\'world\',\'zhengxiaoya\'); // 找到字符串中的第一个\'world\',并把它替换为\'zhengxiaoya\' var c=text.replace(/world/g,\'zhengxiaoya\'); // 用正则表达式去匹配所有的\'world\',替换为\'zhengxiaoya\' var d=text.replace(/hello/gi,\'Hi\') // 忽略大小写替换所有匹配 console.log("---today---",b); // ---today--- Hello zhengxiaoya, Hello world console.log("---today c---",c); // Hello zhengxiaoya, Hello zhengxiaoya console.log("---d----",d); //---d---- Hi world, Hi world