From: John Sampson Date: 2013-01-17T18:05:06+09:00 Subject: Escaped backslashes in input strings - newbie question On 16/01/2013 21:53, Robert Klemme wrote: > On Wed, Jan 16, 2013 at 6:55 PM, John Sampson wrote: >> Input would be, for example, as (part of) a line in a text file, >> "\u99m\UTc". The desired output in this case would be "99mTc". >> >> The objective is to delete the "\u" and the "\U" and any other single >> letters where they are preceded by a backslash. > OK, understood so far. This is what you wrote right from the start. > But what's actually not working? > > robert > If, at IRB, I write: x = "\b99m\BTc" (not \u which gives an 'invalid Unicode escape') and then: a.gsub(/\\./,"") the answer is "\b99mBTc". I am trying to get "99mTc", which I do get provided that I escape "\b" and "\B" with extra backslashes, but in file input these extra backslashes will be absent. I think on investigation that the extra backslashes will not be needed in that, but not necessarily any other, context. I am doing this by experiment, but would rather be able to read a clear exposition on the subject of escapes in the different contexts of file input, IRB, double quoted strings, single quoted strings, Oniguruma and any other contexts affecting the number of backslashes needed. The fact that the ruby-talk archive is full of posts on backslash escapes must be a measure of the widespread confusion on this subject. As an aside, I have trouble with the search engine at the ruby-talk archive - it does not seem to recognise "and" as a Boolean operator. Regards John S