Matt Gregory wrote: > Is this a bug? > > irb(main):032:0> "matt's test".sub(/'/, "\\'") > => "matts tests test" > > It's trying to replace a single quote with an escaped quote. > > Thanks in advance, > Matt irb(main):002:0> puts "matt's test".sub(/'/, "\\\\'") matt\'s test => nil The gsub replacement string is a crazy thing when it comes to escaping, because remember you can put backreferences in it. Any double quoted string needs 2 backslashes to represent a literal backslash, but remember in this context, a literal backslash represents the backreference syntax, so you need to escape it with another "literal backslash" of 2 backslashes. At least, I think that's how I understand it :P -- Posted via http://www.ruby-forum.com/.