s = "one fish two fish" # gsub replaces all occurrences puts s.gsub("fish", "cat") # a block computes each replacement puts "a1b2".gsub(/\d/) { |d| (d.to_i * 2).to_s }
replace every match