From: "David A. Black" Date: 2003-11-24T23:21:37+09:00 Subject: Re: using variables in regular expressions 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") => # David -- David A. Black dblack@wobblini.net