On 2017-03-13 09:02, Robert Klemme wrote:
>
> I think this is not the explanation that OP is looking for. The real
> reason is that for convenience Matz had decided that some sequences do
> work without a second slash, e.g.
>
> irb(main):006:0> '\1'
> => "\\1"
> irb(main):007:0> '\\1'
> => "\\1"
>
> This is convenient when using String#gsub for example
>
> irb(main):008:0> "foobar".gsub(/.(o+)./, '<\1>')
> => "<oo>ar"
> irb(main):009:0> "foobar".gsub(/.(o+)./, '<\\1>')
> => "<oo>ar"
>
> I found it confusing initially and prefer to use \\1 instead of \1
> because that way it is more consistent and easier to read. The
> sequence \1 looks like \n which, in a doubly quoted string, is
> actually a newline.
>
> Kind regards
>
> robert
Hi
Thanks for that info - yes, it's confusing for me - less possibilties 
would be easier to understand (and remember!)
It'll take some more effort to reach the next step...
Is there a (complete) doku with all string expansion details (explained 
at one place) ?
$1 vs  \1,  \xyz (hex, oct, special chars and escaping  and '...' vs 
"..." (and perhaps something more I don't know of)
Didnt find any website with detailed, complete infos.

thank you
Opti


Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>