Reputation: 1965
What would be the ruby code to delete whitespace after every comma in a string? I'm not sure why this didn't work..
.gsub(/[, ]/, ',')
Upvotes: 2
Views: 931
Reputation: 13675
"hello, world".gsub(/, /, ',')
The []
are used to match any of the contained characters. You are replacing every comma or space with a comma.
Upvotes: 6