# Re: Trying to use gsub using variables

**URL:** <https://www.ruby-forum.com/t/re-trying-to-use-gsub-using-variables/149659>\
**Category:** Ruby\
**Created:** [September 27, 2008, 2:57pm UTC](https://www.ruby-forum.com/t/re-trying-to-use-gsub-using-variables/149659 "2008-09-27T14:57:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 27, 2008, 2:57pm UTC](https://www.ruby-forum.com/t/re-trying-to-use-gsub-using-variables/149659/1 "2008-09-27T14:57:12Z")

</div>

----- Original Message ----

> 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
