On Jan 12, 4:39=A0pm, louis <louisju... / gmail.com> wrote:
> user_variable =3D 'some_word' # retrieved from 'gets.chomp'
> cleaned_variable =3D '^' + user_variable + '|\s' + user_variable + '(?!\w)=
'
>
> # print out variable to see if concat worked:
> puts cleaned_variable =A0#=3D> prints out correct regex
>
> p some-sentence-string.gsub(%r{cleaned_variable},'TEST') # =3D> 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 )