We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
#1182 はES2020で、ES2021でreplaceAll
replaceメソッドには正規表現も指定できます。 gフラグを有効化した正規表現を渡すことで、文字列からパターンにマッチするものをすべて置換できます。 https://jsprimer.net/basic/string/#replace-delete
があるので、これの別解としてreplaceAllは追加するのが妥当。 用途的には正規表現を使わずにすべてを置換したい場合となる。 正規表現も渡せるが /g がないとエラーとなることについて触れる。
Regular expressions (RegExp) • JavaScript for impatient programmers (ES2021 edition)
RegExp
Originally posted by @azu in #1220 (comment)
The text was updated successfully, but these errors were encountered:
replaceAllのポイント
tc39/proposal-string-replaceall: ECMAScript proposal: String.prototype.replaceAll でもモチベーションは書かれているけど、正規表現を使わずに全置換したいという感じ。 正規表現だとエスケープが必要となるため面倒となっている。
かつではFirefoxだけ replaceの第三引数で "g" が存在した
"g"
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replace#firefox-specific_notes
Sorry, something went wrong.
事前に正規表現のエスケープも紹介してるので、素直にreplaceAllを追加するだけで問題なさそう。 https://jsprimer.net/basic/string/#regexp-object
ユースケースではString#replaceをHTML文字列をエスケープするで使っている。 String#replaceAllに変更もできるけど、そこまで積極的に変更する理由はなさそう。
Successfully merging a pull request may close this issue.
String.prototype.replaceAll
#1182 はES2020で、ES2021でreplaceAll
があるので、これの別解としてreplaceAllは追加するのが妥当。
用途的には正規表現を使わずにすべてを置換したい場合となる。
正規表現も渡せるが /g がないとエラーとなることについて触れる。
Regular expressions (
RegExp
) • JavaScript for impatient programmers (ES2021 edition)Originally posted by @azu in #1220 (comment)
The text was updated successfully, but these errors were encountered: