From: Jeremy Evans Date: 2010-09-16T05:20:25+09:00 Subject: [ruby-core:32405] Re: [Ruby 1.9-Bug#3833][Open] "foo+bar".gsub("+","\\+") == "foobar" ? On 09/16 04:42, Grant Olson wrote: > Bug #3833: "foo+bar".gsub("+","\\+") == "foobar" ? > http://redmine.ruby-lang.org/issues/show/3833 > > Author: Grant Olson > Status: Open, Priority: Normal > ruby -v: tryruby.org (I'm running 1.8.7 locally, same problem) > > The following gsub with a minus seems to work correctly: > > ??????>> "foo-bar".gsub("-","\\-") > => "foo\\-bar" > > But with a plus, it seems to run incorrectly by stripping the plus: > ??? > >> "foo+bar".gsub("+","\\+") > => "foobar" I think \+ has a special meaning (the last matched group?). You aren't using a regexp as the first argument, so you don't want to use \+. You either want just "+" for a literal + or "\\\\+" for a literal \+. Jeremy