matz / zetabits.com (Yukihiro Matsumoto) wrote:
>
>Hi,
>
>In message "[ruby-talk:6867] Equivalent to Perl's /g and pos()?"
>     on 00/12/07, "Ben Tilly" <ben_tilly / hotmail.com> writes:
>
>|An obvious "solution" is to walk through the string making a
>|copy of what is left at each step.  However doing that turns
>|what should be a O(n) scan through a string into O(n*n) work
>|due to recopying the string - which I find unacceptable.
>|
>|This should be an easy thing to add to Ruby.  Just have a
>|method that returns where the last match left off, and to the
>|match operator add a second optional argument which is the
>|position in the string to start looking for a match at.  Add
>|a \G modifier like Perl's to indicate that the match must
>|start exactly at that position or fail.
>
>I'm afraid I don't get your point, but String#scan or String#index
>might satisfy your request?  In addition, Ruby's regex already have \G
>which works along with String#{scan,gsub,index}.
>
index does it. :-)

For what I want to try I need to be able to take a string and
try to match an arbitrary RE starting at an arbitrary place
in the string.  Looping over calls to index works. :-)

Thanks,
Ben
_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com