From: Thomas Wieczorek Date: 2008-09-01T17:42:23+09:00 Subject: Re: How to replace a string with given pattern? On Mon, Sep 1, 2008 at 10:36 AM, Zhao Yi wrote: > I want to replace a string with the new value on a given regular > pattern. For example: > > "Hello".replace("/H/", "h") #=> hello > You can use String#sub[1] to replace one occurance: "HHello".sub(/H/, "h") #=> "hHello" or gsub[2] to replace all: "HHello".gsub(/H/, "h") [1] http://apidock.com/ruby/String/gsub [2] http://apidock.com/ruby/String/gsub