From: gabriel.birke@... Date: 2006-09-16T08:01:00+09:00 Subject: Re: No regex backreference with four backslashes Paul Lutus schrieb: > > To find out how your strings are being parsed, print them out. Then print > out the result of the regexes directly, rather than relying on an > assertion. > > numbers.gsub(/(2|4)/,"\\\1") > > "1\\\0013\\\0015" > > numbers.gsub(/(2|4)/,"\\\\1") > > "1\\13\\15" > > The best "test suite" is your eyes. I've done that already, the test was only to show the problem: I could not escape chars in the numbers string with a backslash. Anyway, I found the solution, it's five backslashes instead of four. That's a bit counter-intuitive, maybe someone can explain it. Especially when these two are compared: numbers.gsub(/(2|4)/,'\\ \\1') numbers.gsub(/(2|4)/,'\\\\\1') I expected that when I remove the space from the first expression, that my characters would get quoted. instead, the four backslashes get interpreted as two escaped backslashes and the 1 as a literal character. Can somebdoy shed some light on the how and why of this case? Especially, why the solution with the five backslashes doesn't yield double backlashes in the result string?