Es6-regexp-prototype-replace

提供:Dev Guides
2020年6月23日 (火) 08:04時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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