Nicolae Rotaru
Nicolae Rotaru

Reputation: 189

Double strip of spaces in string (ruby)

I have this string:

"item one :value1 , item2: value2,item3 : value3"

how can i obtain this one?:

"item one:value1,item2:value2,item3:value3"

(i need to strip spaces between ","-separated items , and between ":"-separated items)

Upvotes: 0

Views: 84

Answers (1)

noodl
noodl

Reputation: 17408

irb(main):008:0> "item one :value1 , item2: value2,item3 : value3".gsub(/\s*([,:])\s*/,'\1')
=> "item one:value1,item2:value2,item3:value3"

Upvotes: 5

Related Questions