Thank you, all.

Eric l wrote:
> You could try something like this:
>     m = /^.{5,}(ba)/.match(str)
>     p m.begin(1)

In my program, start position is variable such as
     def f(n)
       m = /^.{n,}(ba)/.match(str)
       ...
     end
In this case, /^.{n,}(ba)/ is created for each time.
It is not effective.


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.


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.


Thanks to all your advices.
I'm going to propose to support start position in Regexp#match().

--
makoto kuwata