From: Robert Klemme Date: 2005-10-30T21:52:21+09:00 Subject: Re: chain regex replacement onurturgay@gmail.com wrote: > hi, > I want to make a chain replacement in my String object. For example > a => b > c => d > f => k > > etc. Is there a way to make this replacement in one regex or something > similar? I want to write a custom upcase downcase method, as the > normal one doesnt support unicode (and ruby-unicode doesnt compile on > windows). > > Thanks in advance > onur If you can make changes in one step, i.e. there is no change that will be changed later, you can use the block form of gsub: str.gsub /[acf]/ do |m| case m[0] when ?a; "b" when ?c; "d" when ?f; "k" else raise "error" end end Kind regards robert