Domanda

In Ruby 1.9 I would use String#match(regexp,start_index). I'm sure there must be a (computationally efficient) equivalent in Ruby 1.8, but I can't find it. Do you know what it is?

È stato utile?

Soluzione 2

As far as I can tell, there is no efficient way to match a Regexp against a large string, starting from an arbitrary index, in pure Ruby 1.8.

This seems like a major flaw. I guess the moral of the story is: use Ruby 1.9!

Altri suggerimenti

You could start the regexp with ^.{start_index}

or take the substring first before performing the match.

Alternatively, if you're constrained to using Ruby 1.8, but can install your own libraries then you could use Oniguruma.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top