user1245233 user1245233 - 1 year ago 101
Ruby Question

Remove braces in Ruby

I want to remove the braces so "{test}" becomes "test".
I tried

while "{test}".gsub!(/(\{).*(\})/,""); end

Nothing seems to work.

Answer Source

You have to use \1, not $1

"{test}".gsub /\{(.*)\}/, '\1'

Or, if you just want to delete all curly braces:

"{test}".delete "{}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download