Simon Strandgaard wrote:

> On Thursday 10 June 2004 18:49, Gennady wrote:
> 
>>I am just wondering why String#scan "looses" a group in every match. I
>>would expect the following result:
> 
> 
> when using sub-captures, then #scan returns an array of sub-captures.
> This does not include capture[0].. which is the full-match.
> 
> "abcd".scan(/(.)(.)/)
> #=> [["a", "b"], ["c", "d"]]
> 
> when not using sub-captures at all, then #scan returns only full-matches.
> 
> "abcd".scan(/../)
> #=> ["ab", "cd"]
> 
> --
> Simon Strandgaard
> 

In my original irb session capture I have sub-captures, moreover they 
are nested:

[linux.gfbs:281]gfb> ruby -v
ruby 1.6.8 (2003-10-15) [i686-linux]
[linux.gfbs:282]gfb> irb
irb(main):001:0> a = "a b c d "
=> "a b c d "
irb(main):002:0> a.scan %r{((\S+\s+){2,2})}
ACTUAL   => [["a b ", "b "], ["c d ", "d "]]
I EXPECT => [["a b ", "a ", "b "], ["c d ", "c ", "d "]]

irb(main):003:0>