How do I strip non alphanumeric characters from a string and keep spaces? December 27, 2022 by Tarik Add spaces to the negated character group: @search_query = @search_query.gsub(/[^0-9a-z ]/i, '')