• 點部落
  • 首頁
  • RSS
    • 登入

簡單 Coding

格物、致知、誠意、正心、修身、齊家、治國、平天下

2016-02-28

[javascript][Regular Expression] String.prototype.replace()

  • 178
  • 0

string.replace 的方法,範例:

var result = "hello".replace("he", "my");

結果

myllo

但這篇主要是講使用 Regular Expression 的 replace,再來個範例:

var result = "hello".replace(/e\w/, "abc");

結果

habclo

沒錯,只要將第一個參數改為 /xxx/ 就是  Regular Expression 的  pattern 囉。

接下來說明 replace 的多載方法

...繼續閱讀 »
  • Regular Expression
  • replace
  • 1

系列文章

  • 服務規範
  • 聯絡我們
© 2025 點部落 Ver. 1.0.0.0
電魔小鋪有限公司 製作、維運;登豐數位科技 提供資安檢測