How to match regexp starting from specific character index in Ruby 1.8?
سؤال
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.
لا تنتمي إلى StackOverflow