From: "Gulyás Attila" Date: 2013-01-16T22:35:47+09:00 Subject: Re: Escaped backslashes in input strings - newbie question Check out Regexp.escape -> http://ruby-doc.org/core-1.9.3/Regexp.html#method-c-escape > Regexp.escape( '\foo\bar' ) => "\\\\foo\\\\bar" > Regexp.escape( '\foo\bar' ).gsub /\\\\/,'' => "foobar" hope this helps. regards attila On Wed, Jan 16, 2013 at 1:58 PM, John Sampson wrote: > I am trying to find a way of removing escaped characters in input strings > from a file made by another program. That is to say, two-character sequences > in which the first character is a backslash. > > I would have thought in my naivete that gsub(/\\./,"") would do this, but > no. I am using Ruby 1.9 hence Oniguruma. > > Firstly, are the strings input from a text file treated as single- or > double-quoted? > > Secondly, are there alternatives to gsub? > > Thirdly, are there any *clear* and *exhaustive* treatments of the question > of escaped backslashes in Ruby - in input strings in programs, in IRB, with > single-quoted strings, double-quoted strings and other situations? I guess a > multidimensional table might be useful to determine how to escape a > backslash, if it can be done at all. > > Regards > > John Sampson >