From: "Carlo E. Prelz" Date: 2013-01-17T18:23:22+09:00 Subject: Re: Escaped backslashes in input strings - newbie question Subject: Escaped backslashes in input strings - newbie question Date: Thu 17 Jan 13 06:05:06PM +0900 Quoting John Sampson (jrs.idx@ntlworld.com): > If, at IRB, I write: x = "\b99m\BTc" (not \u which gives an 'invalid > Unicode escape') > and then: a.gsub(/\\./,"") > the answer is "\b99mBTc". That's because, in order to obtain the string you want to obtain, you have to type x = "\\b99m\\BTc" (note the double backslashes). If you then type p x.length you obtain 9. And if you type p x.chars you obtain => ["\\", "b", "9", "9", "m", "\\", "B", "T", "c"] The backslash is ONE character, but it is REPRESENTED as two backslashes. The string you typed instead gives: => ["\b", "9", "9", "m", "B", "T", "c"] \b is the way to represent a backspace. The other backslash disappears because "\B" is not a special backslash sequence, and the non-escaped character is returned. One of the places where you can find a list of the valid backslash sequence is this: http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals (search for 'Backslash Notation') If you ponder on all this jumble with calm, you will see there is a sound logic behind it. If you think this is messy, wait until you meet internationalization! Carlo -- * Se la Strada e la sua Virtu' non fossero state messe da parte, * K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)