------art_102526_1587159.1182383635402
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

"hello".scan(/..*/)
["hello"]

On 6/20/07, Daniel DeLorme <dan-ml / dan42.com> wrote:
>
> Axel Etzold wrote:
> >> irb(main):001:0> "hello".scan(/.*/)
> >> ["hello", ""]
> >>
> >> I was expecting one match, not two, because .* matches everything,
> >> right? Can someone explain why an empty string is also matched?
> >
> > String.scan searches for all occurrences of (any number of any
> > character) here. So zero occurrences is one match.
>
> That doesn't really explain why the regexp finds an extra empty string.
> I know that zero occurrences is one match but after a greedy match that
> matches everything, there should be (logically?) no other match. I am no
> stranger to regexps and the result is counter-intuitive to me; I would
> consider it a bug. Or at least a very very peculiar behavior.
>
> Daniel
>
>

------art_102526_1587159.1182383635402--