From: sabbyxtabby@... (Sabby and Tabby) Date: 2003-11-26T03:52:11+09:00 Subject: Re: using variables in regular expressions "Robert Klemme" wrote: > "Damphyr" schrieb im Newsbeitrag > news:3FC2104E.7080607@freemail.gr... > > > > repo.collect!{|entry| > > entry.gsub(/{variable_with_the root_I_want_to_substitute}/,"") > > } > > using gsub! is more efficient and better use %r{} because Regexp.quote > does not quote "/": > > repo.each {|entry| > entry.gsub!(%r{#{Regexp.quote(variable_with_the > root_I_want_to_substitute)}},"") > } Don't need %r{}. A slash "/" in interpolated variables is harmless. Add anchor, unless removing root from middle of path is desirable. Add /o modifier: entry.gsub!(/^#{Regexp.quote(root)}/o, "")