From: Raul Jara Date: 2010-03-03T11:50:55+09:00 Subject: Re: Find and replace with values from array with gsub Raul Jara wrote: > @full_text_array.each_with_index do |original_name, i| > @full_text.gsub!(original_name, @new_link_array[i]) > end > > > Although if you have "Derek Jeter Derek Jeter" fifty times in a row > you'll end up doing a lot of extra work. You might want to do something > like: > > results = @full_text.scan(/([A-Z]+[a-zA-Z]* [A-Z]+[a-zA-Z]*)/) > > names_links = {} > > results.each do |name| > unless names_links[name] > names_links[name] = method_to_construct_link_for_name(name) > end > end > > results.each_pair do |name, link| > @full_text.gsub!(name, link) > end Stupid hitting submit before I meant to. The first post contains at least one typo, and also I meant to add that I hope that helps. -Ra炭l -- Posted via http://www.ruby-forum.com/.