Andreas Schwarz wrote: > Patrick Gundlach wrote: > > Dear Ruby-hackers, > > > > simple problem: replace a certain letter with \' (backslash apostrophe). > > > > ------------------------------ > > #!/usr/bin/ruby -w > > puts "hello".gsub!(/h/,"\\'") > > ------------------------------ > > > > result: elloello > > > > I would like to get: > > > > \'ello > > > > What should I try? > > puts "hello".gsub!(/h/,"\\\\'") > > "\\" is reserved for backreferences. In the above case \' (slash quote) are interpreted as post-match. Other useful things in replacement string: \` pre-match \+ last-capture \& match -- Simon Strandgaard