目录

RegExp.prototype.replace()

替换匹配的模式后,此方法返回一个新字符串。

语法 (Syntax)

str.replace(regexp|substr, newSubStr|function)           

参数的细节 (Parameter Details)

  • Regexp - 正则表达式对象。

  • Substr - 要替换​​的字符串。

  • newSubStr - 替换字符串。

  • function - 创建新字符串的函数。

返回值 (Return Value)

替换所有匹配后的新字符串。

例子 (Example)

var str = 'Good Morning'; 
var newstr = str.replace('Morning', 'Night'); 
console.log(newstr);  

输出 (Output)

Good Night     
↑回到顶部↑
WIKI教程 @2018