"Simon Strandgaard" <neoneye / adslhome.dk> schrieb im Newsbeitrag
news:20040530221337.39b1ecfa.neoneye / adslhome.dk...
> Patrick Gundlach <clr1.10.randomuser / spamgourmet.com> wrote:
> > Andreas Schwarz <usenet / andreas-s.net> writes:
> >
> > > puts "hello".gsub!(/h/,"\\\\'")
> > >
> > > "\\" is reserved for backreferences.
> >
> > Hello Andreas,
> >
> > Oh, yes. This works fine. Thank you (and of course Simon).
> >
>
> Another way to obtain same result.. without extra escaping.
>
> puts "hello".gsub!(/h/) {|m| "\\'"}

Or

>> puts "hello".gsub!(/h/, %q{\\\\'})
\'ello

Note:

>> puts  %q{\\\\'}
\\'


You need an escaped backslash to prevent interpretation of it in the
replacement pattern.

    robert