From: Ryan Pavlik Date: 2003-05-30T07:07:36+09:00 Subject: Re: substitution weirdness On Fri, 30 May 2003 06:58:35 +0900 Ian Macdonald wrote: > irb(main):119:0> foo = "'123" > => "'123" > irb(main):120:0> foo.gsub(/'/, "\\'") > => "123123" > > Why does the apostrophe get replaced with a copy of the text that > follows it? \' has special meaning ("after the match", iirc, which makes sense here). A string "" requires you to escape \, as \\, so: "\\'" => \' => after-the-match substitution Try: foo.gsub /'/, "\\\\'" => "\\'123" (Remember that "\\'" is \', because \ is escaped.) This double-escapes the backslash for the results you want. (Try printing the result when you get it.) hth, -- Ryan Pavlik "Spinal hazards *are* hazardous..." - 8BT