var a = "The boy is gay.";
var b = /boy/;
console.log(b) —— /boy/ x相当于给他加一个 "" 转义
var c = a.replace(b, function (s) { s是a中匹配到的元素即在a中找到b
return "girl";
});
console.log(c) —— 输出 The girl is gay.
2024-01-23 13:18:34
var a = "The boy is gay.";
var b = /boy/;
console.log(b) —— /boy/ x相当于给他加一个 "" 转义
var c = a.replace(b, function (s) { s是a中匹配到的元素即在a中找到b
return "girl";
});
console.log(c) —— 输出 The girl is gay.