Skip to content
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

Merged
merged 14 commits into from
May 9, 2021
Merged

feat(string): String#replaceAllを追加 #1314

merged 14 commits into from
May 9, 2021

Conversation

azu
Copy link
Collaborator

@azu azu commented May 9, 2021

対象ページ

変更点

  • String#replaceAllの追加
  • Node.js 16をCIに追加(String#replaceAllはNode 15以降の対応)

fix #1310

@bot-user
Copy link

bot-user commented May 9, 2021

Deploy preview for js-primer ready!

Built with commit 6264f8b

https://deploy-preview-1314--js-primer.netlify.app

@@ -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"`という文字列にマッチします。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このサンプル、微妙にgがある方が自然になっているので、
もうちょっと別の例にするのが良いかもしれない。


`replace`メソッドの第二引数にはコールバック関数を渡せます。
`String#replace`と`g`フラグ付きの正規表現を使った場合との違いとして、
`String#replaceAll`メソッドでは、正規表現を使わずにすべてを置換できます。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要点はこれなので、細かいところはちょっと解説していない。
正規表現も渡せるとか第2引数とか、は基本replaceと同じなので。


`replace`メソッドの第二引数にはコールバック関数を渡せます。
`String#replace`と`g`フラグ付きの正規表現を使った場合との違いとして、
`String#replaceAll`メソッドでは、正規表現を使わずに文字列を使ってすべてを置換できます。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かい言い回しが気になるけど、あんまり最適なのが思いつかないな。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すべてを置換できます。

繰り返し置換 という表現も考えたけど、replaceAllなのですべてとか全部とかソッチのほうが合う感じがした

@azu azu merged commit 88464f1 into asciidwango:master May 9, 2021
@azu azu deleted the feature/1311 branch May 9, 2021 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String.prototype.replaceAll
2 participants