thisiscrazy4
thisiscrazy4

Reputation: 1965

Ruby: Delete space after every comma?

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

Answers (1)

Benoit Garret
Benoit Garret

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

Related Questions