Just a quick post. I’ve converted the C code from the wikipedia entry (this version) on the Boyer-Moore string search algorithm to Ruby. I’ve extended it to support searches on token arrays and regular expressions.
The regular-expression token matching is a bit of a hack and will be fairly slow because every hash miss is compared against every regular expression key. You probably shouldn’t use the regular expression token search for anything more than a toy.
Boyer-Moore string search algorithm in Ruby
Just a quick post. I’ve converted the C code from the wikipedia entry (this version) on the Boyer-Moore string search algorithm to Ruby. I’ve extended it to support searches on token arrays and regular expressions.
You can find the code on github.
Usage:
Examples:
Basic search in string:
You can also search an array of tokens:
A token can be a regular expression:
Notes:
The regular-expression token matching is a bit of a hack and will be fairly slow because every hash miss is compared against every regular expression key. You probably shouldn’t use the regular expression token search for anything more than a toy.
Download the Boyer-Moore string search algorithm in Ruby.