From: Hugh Sasse Date: 2006-11-24T01:53:41+09:00 Subject: Re: double-slashes in input causing trouble On Fri, 24 Nov 2006, Jeremy Wells wrote: [...] > The problem is that if the section contains "\\" which mine does in places, > ruby replaces these with a single "\" without my asking it to. > > Here is the basics of the program: > body = "" > File.open(input, 'r') do |file| > body = file.read > end > > if body =~ /^section\sheader(.*)section\sfooter/mi > original_section = $1 > new_section = bit_at_top + original_section > new_body = body.sub(original_section, new_section) new_body = body.sub(Regexp.new(Regexp.quote(original_section)), new_section) > > File.open(input,'w') do |file| > file.write new_body > end > end # Hugh