On 18.11.2007 19:57, Robert Dober wrote:
> On Nov 18, 2007 6:29 PM, Wolfgang N=E1dasi-Donner <ed.odanow / wonado.de>=
 wrote:
>> Robert Dober wrote:
>>> ...wonder how this would scale if there were a Regexp#match allowing =
for an offset.
>>
>> ...which will come in Ruby 1.9:
>>
>> C:\Dokumente und Einstellungen\wolfgang>irb19
>> irb(main):001:0> "abcdef".match(/./,3)
>> =3D> #<MatchData "d">
>>
> Great :)
>=20
> I have written a 1.9 test and still lookahead is much better, I am
> surpprised as I got rid of all fancy stuff in the
> bf_sub method going back to my Regexp stuff happily again.

IMHO it is not surprising because the lookahead method uses one method=20
(scan) which is implemented in C while you create a lot of temporary=20
objects and also start scanning at *every* position in the string.=20
Usually regexp engines are implemented much smarter than we can do in=20
short method.  I am sure you have heard of Boyer Moore and Knuth Morris=20
Pratt algorithms... :-)

>   def bf_sub substr
>     r =3D []
>     size.times do |i|
>       s =3D
>         substr.match(self,i)
>       r << ( s && s[0] )
>     end
>     r.compact
>   end

Kind regards

	robert