From: Brian Candler Date: 2010-01-14T19:15:43+09:00 Subject: Re: Ruby Regex Robert Klemme wrote: > For me there is actually something weird about Ruby's escape handling > - but it's something else: in some circumstances Ruby allows you to > *omit* a backslash which is meant to be convenient (I believe) but > which leads to a certain inconsistency: > > irb(main):014:0> '\1' # this might be seen as surprising > => "\\1" I think the principle is "single quoting does the absolute minimum amount of dequoting". However it *has* to support a way to get a single-quote within a single-quoted string, and they chose \'. As a consequence, it *has* to support \\ to get a single backslash within a single-quoted string. The question then is, should any other sequence like \1 raise an error, or return literal \ and 1 ? The alternative would have been to use two single quotes where you want a single quote within a string: 'It''s that time of day' I quite like that, but arguably it's just confusing in a different way. -- Posted via http://www.ruby-forum.com/.