var re = /apples/gi; // 正则表达式表示全局忽略的大小写的目标项
var str = "Apples are round, and apples are juicy."; var newstr = str.replace(re, "oranges");
把字符串中所有的apples全部替换为oranges并赋予新字符串
console.log(newstr); // 结果为:oranges are round, and oranges are juicy.
var re = /apples/gi; // 正则表达式表示全局忽略的大小写的目标项
var str = "Apples are round, and apples are juicy."; var newstr = str.replace(re, "oranges");
把字符串中所有的apples全部替换为oranges并赋予新字符串
console.log(newstr); // 结果为:oranges are round, and oranges are juicy.