Es6-regexp-prototype-replace
提供:Dev Guides
ES6-RegExp replace()
このメソッドは、一致したパターンを置換した後、新しい文字列を返します。
構文
str.replace(regexp|substr, newSubStr|function)
パラメータの詳細
- Regexp -正規表現オブジェクト。
- Substr -置換される文字列。
- newSubStr -置換文字列。
- function -新しい文字列を作成する関数。
戻り値
すべての一致を置換した後の新しい文字列。
例
var str = 'Good Morning';
var newstr = str.replace('Morning', 'Night');
console.log(newstr);
出力
Good Night