简体   繁体   中英

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?

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 .

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM