From: Phrogz Date: 2008-01-13T13:59:59+09:00 Subject: Re: using a variable as 1st param in gsub On Jan 12, 4:39 pm, louis wrote: > user_variable = 'some_word' # retrieved from 'gets.chomp' > cleaned_variable = '^' + user_variable + '|\s' + user_variable + '(?!\w)' > > # print out variable to see if concat worked: > puts cleaned_variable  #=> prints out correct regex > > p some-sentence-string.gsub(%r{cleaned_variable},'TEST') # => prints > out sentence unchanged %r{foo} is the same as /foo/...you're using the name of the variable, not the contents. You want: /#{foo}/ or %r{#{foo}} or %r|#{foo}| or ... or Regexp.new( foo )