-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(string): String#replaceAllを追加 #1314
Conversation
Deploy preview for js-primer ready! Built with commit 6264f8b |
@@ -1035,15 +1056,15 @@ const 置換した結果の文字列 = 文字列.replace(/(パターン)/, (all, | |||
|
|||
例として、`2017-03-01`を`2017年03月01日`に置換する処理を書いてみましょう。 | |||
|
|||
`/(\d{4})-(\d{2})-(\d{2})/`という正規表現が`"2017-03-01"`という文字列にマッチします。 | |||
`/(\d{4})-(\d{2})-(\d{2})/g`という正規表現が`"2017-03-01"`という文字列にマッチします。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このサンプル、微妙にgがある方が自然になっているので、
もうちょっと別の例にするのが良いかもしれない。
source/basic/string/README.md
Outdated
|
||
`replace`メソッドの第二引数にはコールバック関数を渡せます。 | ||
`String#replace`と`g`フラグ付きの正規表現を使った場合との違いとして、 | ||
`String#replaceAll`メソッドでは、正規表現を使わずにすべてを置換できます。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要点はこれなので、細かいところはちょっと解説していない。
正規表現も渡せるとか第2引数とか、は基本replaceと同じなので。
source/basic/string/README.md
Outdated
|
||
`replace`メソッドの第二引数にはコールバック関数を渡せます。 | ||
`String#replace`と`g`フラグ付きの正規表現を使った場合との違いとして、 | ||
`String#replaceAll`メソッドでは、正規表現を使わずに文字列を使ってすべてを置換できます。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かい言い回しが気になるけど、あんまり最適なのが思いつかないな。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すべてを置換できます。
繰り返し置換 という表現も考えたけど、replaceAllなのですべてとか全部とかソッチのほうが合う感じがした
対象ページ
変更点
fix #1310