From: Marnen Laibow-Koser Date: 2010-01-14T05:24:32+09:00 Subject: Re: Ruby Regex Brian Candler wrote: > Marnen Laibow-Koser wrote: >> The problem is that Ruby "helpfully" does another level of >> escaping > > It's necessary because it lets you use sequences like \n in > double-quoted strings, and \" if you want a double-quote, and \#{expr} > if you want literally # { expr } rather than interpolation. > >> so that "\\&" is equivaIent to "\&", whereas it should simply >> take the escape at face value and consider it equivalent to the two >> characters \ and &. > > Which is what happens in single-quoted strings. But you can't put any > control character sequences like \n in those. > I know that. >> For real fun, try concatenating two strings, the first of which ends in >> a backslash. It's insane. > > a = "abc\\" # that's a string ending with one backslash > b = "def" > c = a + b > > Looks OK to me. > And to me too, when I just now tried it. I *did* run into a problem with this at one point, but I can't now reproduce it. Perhaps it was actually a gsub issue. I'm glad to know that Ruby's backslash handling is not as weird as I'd thought. Thanks for the correction. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.