On 25.11.2007 18:58, makoto kuwata wrote:
> Robert Klemme wrote:
>> Another alternative is to use String#scan -
> 
> String#scan is useful only when regexp pattern is fixed.
>     input.scan(/FIXED-REGEXP/) do ... end
> Using String#scan, it is not able to change regexp pattern
> in the loop.

But in various situations it is possible to use a unified regexp for 
scanning or a regexp that comprises all other patterns.

> Axel Etzold wrote:
>>                temp=string[start_pos..-1]
>>                ref=self.match(temp)
>>                return temp.index(ref[0])+start_pos
> 
> In this solution, temp substring is created every time.
> If input string is long, it is not efficient.

This is not true.  Creating a substring is fairly cheap because the 
character buffer is not copied (copy on write).

> I'm going to propose to support start position in Regexp#match().

For the time being it's faster to use one of the other alternatives. 
Also, with the new regexp engine in 1.9 your feature might be present 
already.

Kind regards

	robert