Bruce Xinda Lin Bruce Xinda Lin - 10 months ago 43
Ruby Question

Get content between { } braces

How can I get the content in between "{ }" in Ruby? For example,

I love {you}

How can I fetch the element "you"? If I want to replace the content, say change "you" to "her", how should I do that? Probably using


Regular expressions are the way to go with gsub. Something like:

existingString.gsub(/\{(.*?)\}/) { "her" }