Hi --

On Thu, 31 May 2007, Andrew Stewart wrote:

> Hello,
>
> I am running into difficulties trying to use a variable in a substitution. 
> Here's an example:
>
> var = 'October'
> '30 May 2007'.sub( /(\d+)\s(\w+)\s(\d+)/, '\1 #{var} \3' )
>
> Here I would like to get '30 October 2007'.  The back-references, i.e. \1 and 
> \3, only work within single quotation marks.  But the interpolation only 
> works within double quotation marks.  What to do?

Try:

   "\\1 #{var} \\3"


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)