From: Tachikoma Date: 2008-07-16T15:55:20+09:00 Subject: Re: RegEx stuff On Jul 16, 1:08 pm, Justin To wrote: > a = [["a^b^^"], ["c&def"]] > b= [] > > a.to_s.each_byte { |byte| (b.push(byte.chr) if !b.include?(byte.chr)) if > byte.chr.match(/\W+/) } > > b.each do |c| >   a=a.to_s.gsub(c, "\\#{c}").to_a >   end > > p a > > => ["a\\^b\\^\\^c&def"] > > How come the & does not get subbed with '\\&' ?? > > I'm basically trying to substitute any special character with > '\\#{special_character}' > > THANKS! > -- > Posted viahttp://www.ruby-forum.com/. try a=a.to_s.gsub(c, "\\\\#{c}").to_a "\\" will present as '\' '\&' will present as '&'