On Jun 21, 2007, at 9:47 AM, Stephen Ball wrote:

> On 6/20/07, Daniel DeLorme <dan-ml / dan42.com> wrote:
>> 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
>
> It's because the pattern /.*/ matches everything, including the
> absence of everything. Yes, with the proper regexs you can indeed have
> tea and no tea at the same time. Certainly peculiar, but occasionally
> useful.
> ...
> -- Stephen

That still doesn't really explain why "hello".scan(/.*/) => ["hello",  
""]

Why wouldn't it be ["hello", "", "", "", "", "", "", "", "", "", "",  
"", ... ] since I (or rather the OP) could continue to match zero  
characters (bytes) at the end of the string forever?  It does seem  
that it might be that a termination condition is checked a bit later  
than it should be in this case.

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com