Ruby 替换为字符串的问题

Ruby 替换为字符串的问题,ruby,gsub,Ruby,Gsub,我试图执行如下代码: template = " ... here html tags [sitename] ... here html tags " template = template.gsub(/\[sitename\]/,"http://google.com") 但它不起作用。我犯了什么错误?你能描述一下它是如何不起作用的吗 在ruby 1.9.2中,我得到了我所期望的命令 puts template 给予 ... here html tags http://google.com

我试图执行如下代码:

template = "
... here html tags
[sitename]
... here html tags
"

template = template.gsub(/\[sitename\]/,"http://google.com")

但它不起作用。我犯了什么错误?

你能描述一下它是如何不起作用的吗

在ruby 1.9.2中,我得到了我所期望的命令

puts template
给予

... here html tags
http://google.com
... here html tags