Ruby - Escape Parenthesis
- by Todd Horrtyz
I can't for the life of me figure this out, even though it should be very simple.
How can I replace all occurrences of "(" and ")" on a string with "\(" and "\)"?
Nothing seems to work:
"foo ( bar ) foo".gsub("(", "\(") # => "foo ( bar ) foo"
"foo ( bar ) foo".gsub("(", "\\(") # => "foo \\( bar ) foo"
Any idea?