If I have a string like so ..
There is a lot of white space.
And I want to remove all the unwanted space in Ruby’s regex.. How do you identify white space and remove it so that there will still be at least one white space between all the words?
So far I have :
gsub(/\s{2,}/, '')
But as you can see that collapses several words into each other.
You’re close. After trimming whitespace off the left and right,
replace any sets of multiple spaces with a single space. This, of course, assumes you’re only dealing with actual spaces.