Hi --

On Mon, 24 Nov 2003, Damphyr wrote:

> Being lazy, forgetful and generally very bad with regular expressions 
> leads me to post this question:
> 
> How can I use the contents of a variable as a pattern in a regular 
> expression?
> 
> I get a list of files from a set of paths and I want to do the following
> 
> repo=list_files paths
> repo.collect!{|entry|
> 	entry.gsub(/{variable_with_the root_I_want_to_substitute}/,"")
> }

Use #{...} (same syntax as string interpolation):

  irb(main):002:0> s = "h."
  => "h."
  irb(main):003:0> /#{s}/.match("hi")
  => #<MatchData:0x400d2004>


David

-- 
David A. Black
dblack / wobblini.net