From: maestroiut-rubytalk@... Date: 2008-09-27T21:55:52+09:00 Subject: Re: Trying to use gsub using variables ----- Original Message ---- > From: jackster the jackle > To: ruby-talk ML > Sent: Saturday, September 27, 2008 2:22:55 PM > Subject: Re: Trying to use gsub using variables > > thanks guys...I'm making progress but what I have been slowly leading up > to is searching using a variable then replacing it with a variable. > > acl = "now is the time" > x = time > y = TEST you meant, didn't you? x = "time" y = 'TEST' > > acl.gsub(/x/,y) > How do I get gsub to use the value of x rather "x" itself in my match? You can use the #{ruby code} notation that evaluates the ruby code and inserts the value like in double quoted strings. In your case that would be something like: acl.gsub(/#{x}/,y) Though the content of x should not be interpreted, you should write: acl.gsub(/#{Regexp.escape(x)}/,y) > thanks you are most welcome, Christophe > > Jackster > -- > Posted via http://www.ruby-forum.com/.