2010/3/25 Jesù¸ Gabriel y GaláÏ <jgabrielygalan / gmail.com>: > On Thu, Mar 25, 2010 at 9:09 PM, Jesse B. <jessebos / aol.com> wrote: >> Thank you Jesus, >> Your solution is much more elegant. >> However it leaves a blank line where my string was. any idea how to >> close that gap? >> >> i.e. >> >> opening text >> --/text to delete/-- >> closing text >> >> now renders as: >> >> opening text >> >> closing text >> >> and what I am going for is: >> >> opening text >> closing text >> >> thanks again for all of your help! > > infile = File.read("input.txt") > File.open("output.txt", "w") do |outfile| > utfile.puts infile.split(%r{\n?--/.*?/--}m).join > end > > Two changes: > > - I added an optional \n at the beggining of the matched area to cover > that case, although there might be other corner cases. > - I joined the array before writing it, because puts with an array > prints a newline between each element. If you slurp in the whole file anyway then you can do content = File.read "input.txt" content.gsub! %r{--/.*?/--}m, '' File.open "output.txt", "w" do |out| out.write content end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/