From: Austin Ziegler Date: 2003-05-13T12:02:06+09:00 Subject: Re: Regexp: why does (re)* return only last repetition? On Tue, 13 May 2003 07:54:02 +0900, Brian Candler wrote: > On Tue, May 13, 2003 at 07:29:24AM +0900, Austin Ziegler wrote: >> You changed the pattern. >> >> 1 | pat = "[a-z\\]" >> 2 | str = "abcd\\efgh" >> 3 | index = /#{pat}/ =~ str >> 4 | p index >> >> line 3 results in: >> RegexpError: premature end of regular expression: /[a-z\]/ > Double-quoted strings interpolate backslashes: so in your example > pat contains: > [a-z\] No: irb(main):001:0> "[a-z\\]" => "[a-z\\]" It's rather irrelevant anyway, as the *exact same behaviour* happens with single-quoted strings (change line 1 to '' instead of ""). >> Change the pattern to "[\\a-z]" and the error goes away. > Yes, that's > [ \ a - z ] No: irb(main):008:0> "[\\a-z]" => "[\\a-z]" > I guess '\a' is treated as just 'a' in a character class. No: irb(main):009:0> /[\a]/ =~ "abc\a" => 3 This behaviour is in both 1.6.8 and 1.8.0 (2003-05-09). I really think that it's a bug because [\\a-z] and [a-z\\] should be semantically equivalent. It works when done as a literal; it doesn't work when substitution is done. -austin -- Austin Ziegler, austin@halostatue.ca on 2003.05.12 at 22:54:26