Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
gsub を正しく使用できません。
このコードを考えると:
"replace me".gsub(/replace me/, "this \\0 is a test")
結果は次のとおりです。
"this replace me is a test"
しかし、私が期待しているのは次のとおりです。
"this \0 is a test"
gsub を使用して必要な結果を得るにはどうすればよいですか?
別の円記号でエスケープして、必要なことgsubがわかるようにします"\\0"。
gsub
"\\0"
"replace me".gsub(/replace me/, "this \\\\0 is a test")
(編集)"\0"バイトを意味する場合は、次のようにします0x00。
"\0"
0x00
"replace me".gsub(/replace me/, "this \0 is a test")