From: "daniel åkerud" Date: 2007-09-19T23:59:34+09:00 Subject: Re: replace multiple patterns of a string in single pass ------=_Part_21561_14653803.1190213962370 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/19/07, Jeff wrote: > > On Sep 19, 5:13 am, Vellingiri Arul > wrote: > > Dear Friends, > > How can I replace multiple patterns of a string in single pass. > > > > by > > Vellingiri > > -- > > Posted viahttp://www.ruby-forum.com/. > > Try String#gsub > > Jeff > > > What you need to do is put multiple regular expressions into String#gsub method by first calling Regexp::union. At each match you need to find out which regular expression did the match and provide it with the replacement string. So you need to use this version of gsub: str.gsub(pattern) {|match| block } => new_str /D ------=_Part_21561_14653803.1190213962370--