From: J-H Johansen Date: 2007-08-28T17:14:11+09:00 Subject: Re: Conducting Regular Expressions on a text file On 8/28/07, Peter Marks wrote: > Follow up question: > > How might I be able to make multiple placeholders within a text file? I > thought this would work: > > File.open("source.txt", "r") do |src| > File.open("sink.txt", "w") do |sink| > src.each_line { |line| sink.write(line.gsub(/placeholder/, "word")) > sink.write(line.gsub(/placeholder2/, > "word2")) > } > end > end > > , but my newbie assumptions were mistaken. Any ideas? Nearly there though ;-) I think you can connect all the gsub's together for that effect. File.open("source.txt", "r") do |src| File.open("sink.txt", "w") do |sink| src.each_line { |line| sink.write(line.gsub(/placeholder/, "word").gsub(/placeholder2/,"word2")) } end end You could also create a Hash for placeholder => word in case you have a lot of things that needs to be changed. > Thanks, > > Peter -- J-H Johansen -- There are 10 kinds of people in the world: Those who understand binary and those who don't...