문제

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?

도움이 되었습니까?

해결책 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!

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top