this regex will replace instance of 1 or more white spaces with 1 white space, p.s \s will replace all white space characters which includes \s\t\r\n\f:
a_string.gsub!(/\s+/, ' ')
Similarly for only carriage return
str.gsub!(/\n/, " ")
First replace all \n with white space, then use the remove multiple white space regex.