From: Zhao Yi Date: 2008-09-01T17:58:32+09:00 Subject: Re: How to replace a string with given pattern? Thomas Wieczorek wrote: > 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 ok thanks. -- Posted via http://www.ruby-forum.com/.