How do I replace a group of reserved chars into " " in Ruby on Rails?

regex, ruby, ruby-on-rails

Solution

This is what `tr` is for:

keyword.tr '-+&|!(){}[]^"~*?:\\', " "
#=> "                                   "

Problem

I want to replace the following reserved chars into spaces: ``` + - & | ! ( ) { } [ ] ^ " ~ * ? : \ ``` This is my code, but it doesn't work. Did I miss anything? ``` keyword = keyword.gsub(/\\+-&\\|!\\(\\)\\{\\}\\[\\]\\^"~\\*\\?:\\\\/, ' ') ```

Original source