I don’t see immediate answers to this in the ML but others might still
have answered it already.
On Fri, Aug 31, 2012 at 5:50 PM, Luke P. [email protected]
I can understand why I need to double escape the + to get + in the
output but shouldn’t (1) above at least print “hi + bye”?
There are two levels of escapes and it happens that the backslash is
the escape character for both levels:
- string (i.e. what makes “\n” create a string with the line
- regular expression replacement pattern (e.g. \1 as a backreference)
If you want to have a literal backslash in the result, you need to
escape it, i.e. you need this in the replacement string
To get that, you need to escape each backslash so string escaping does
not eat it, so you do
irb(main):005:0> puts “\”
irb(main):006:0> puts “\\”