From: Brian Candler Date: 2003-05-13T16:51:08+09:00 Subject: Re: Regexp: why does (re)* return only last repetition? On Tue, May 13, 2003 at 04:10:36PM +0900, Brian Candler wrote: > And single-quoted strings have the same issue it turns out: > > a = '\\' > p a.length # => 1 > > I am not sure why that should be, since '\n'.length is 2. I think you may > have uncovered a bug here. I just realised, it's not a bug: it's necessary to give a mechanism for inserting a single quote within a single-quoted string. This is done by escaping it with backslash: '\''.length #>> 1 (just a single quote) But that in turn means that to get a literal backslash it also needs to be escaped: '\\'.length #>> 1 (just a backslash) All other backslash-X sequences are inserted as the backslash and the X. Regexps are subject to certain quoting rules too. Try: z = /ab\c/ puts z.inspect This program crashes under both ruby 1.6 ("unterminated regexp meets end of file) and 1.8 ("unterminated string meets end of file"). But z = /ab\d/ works. Somebody care to explain that one? :-) Regards, Brian.