{"description":"sub\uff1a\u30d1\u30bf\u30fc\u30f3\u306b\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u305f\u6700\u521d\u306e\u90e8\u5206\u3092\u7f6e\u304d\u63db\u3048 sub(pattern, replace) \u306fpattern\u306b\u30de\u30c3\u30c1\u30f3\u30b0\u3057\u305f\u6700\u521d\u306e\u6587\u5b57\u5217\u306e\u307f\u3092replace\u306b\u7f6e\u304d\u63db\u3048\u305f\u6587\u5b57\u5217\u3092\u8fd4\u3059\u3002 sub!\u306a\u3089\u7834\u58ca\u7684\u306b\u7f6e\u304d\u63db\u3048\u308b\u3002 str = \"apple orange\" # sub\u306f\u5143\u306e\u6587\u5b57\u5217\u306f\u305d\u306e\u307e\u307e p str.sub(\"a\", \"@\") #=> \"@pple orange\" p str #=> \"apple orange\" # sub!\u306f\u5143\u306e\u6587\u5b57\u5217\u5f8c\u3068\u7f6e\u304d\u63db\u3048\u308b p str.sub!(\"a\", \"@\") #=> \"@pple orange\" p str #=> \"@pple orange\" g\u2026","version":"1.0","published":"2026-06-29 00:00:00","blog_title":"\u30e9\u30f3\u30c9ML","provider_name":"Hatena Blog","height":"190","image_url":null,"author_name":"round-rand","url":"https://ml-rand-note.hatenablog.com/entry/ruby/string-replace","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fml-rand-note.hatenablog.com%2Fentry%2Fruby%2Fstring-replace\" title=\"\u3010Ruby\u3011\u6587\u5b57\u5217\u306e\u7f6e\u63db(sub\u30fbgsub\u30fbdelete\u30fbtr) - \u30e9\u30f3\u30c9ML\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","title":"\u3010Ruby\u3011\u6587\u5b57\u5217\u306e\u7f6e\u63db(sub\u30fbgsub\u30fbdelete\u30fbtr)","author_url":"https://blog.hatena.ne.jp/round-rand/","type":"rich","blog_url":"https://ml-rand-note.hatenablog.com/","provider_url":"https://hatena.blog","width":"100%","categories":["Ruby"]}