From: John Sampson Date: 2013-01-16T23:52:22+09:00 Subject: Escaped backslashes in input strings - newbie question This is a multi-part message in MIME format. --------------060207050000060209020305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I should have mentioned that I was using gsub! It does look as if I will need a non-Ruby program to massage the file input. On 16/01/2013 13:42, Alexander McMillan wrote: > Firstly, gsub does not make the removal of characters permanent, try gsub! > Secondly, if you control the other program why not from there put the > input into your own designed string delimiters instead of single and > double quotes doing away with the need to use escape backslashes > within the string? > > > > > Date: Wed, 16 Jan 2013 21:58:13 +0900 > > From: jrs.idx@ntlworld.com > > Subject: Escaped backslashes in input strings - newbie question > > To: ruby-talk@ruby-lang.org > > > > 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 > > --------------060207050000060209020305 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
I should have mentioned that I was using gsub!

It does look as if I will need a non-Ruby program to massage the file input.

On 16/01/2013 13:42, Alexander McMillan wrote:
Firstly, gsub does not make the removal of characters permanent, try gsub!
Secondly, if you control the other program why not from there put the input into your own designed string delimiters instead of single and double quotes doing away with the need to use escape backslashes within the string?
 

 
> Date: Wed, 16 Jan 2013 21:58:13 +0900
> From: jrs.idx@ntlworld.com
> Subject: Escaped backslashes in input strings - newbie question
> To: ruby-talk@ruby-lang.org
>
> 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
>

--------------060207050000060209020305--