From: dblack@... Date: 2003-05-14T03:21:23+09:00 Subject: Re: Regexp: why does (re)* return only last repetition? Hi -- On Wed, 14 May 2003, Austin Ziegler wrote: > Okay, I think the problem here is: > > a = "[a-z\\]" > b = /#{a}/ > > When the RE is being built, a is being interpolated again. If I've > built my regular expression source string properly, it should NOT be > interpolated again. Is there any way to build a RE from a string > which does not reinterpolate the string? Is there a way to add such > a functionality if it does not exist? I'm not sure what you mean by "interpolate again" (or reinterpolate). I think everything is happening just once: you've created a string ([a-z\]), and you're interpolating it into a regex. > Frankly, /#{a}/ for the above string should be no different than > /[a-z\\]/. Except... a is a 6-char string ([a-z\]), and the contents of the regex there is 7 characters :-) There's no way for Ruby to backtrack and know that, when you created the string, you typed \ twice. You might have produced the string this way: a = [91, 97, 45, 122, 92, 93].map {|c| c.chr}.join # [a-z\] David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav