boyer-moore string search algorithm in ruby (supports tokens and regexps)
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples added readme etc Oct 27, 2010
lib rm'd extra files Oct 27, 2010
spec added readme etc Oct 27, 2010
.gitignore added ignores Oct 27, 2010
README.mkd tweak to readme Oct 27, 2010
Rakefile initial import Oct 26, 2010



The Boyer-Moore string matching algorithm.

Ported to ruby from wikipedia's c code, but geared towards a token search rather than merely characters.

Usage:, needle)   # returns index of needle or nil


Basic search in string:"ANPANMAN", "ANP")   # => 0"ANPANMAN", "ANPXX") # => nil"foobar", "bar")     # => 3

You can also search an array of tokens:["<b>", "hi", "</b>"], ["hi"])         # => 1["bam", "foo", "bar"], ["foo", "bar"]) # => 1["bam", "bar", "baz"], ["foo"])        # => nil 

A token can be a regular expression:["Sing", "99", "Luftballon"], [/\d+/]) == 1["Nate Murray", "5 Pine Street", "Los Angeles", "CA", "90210"], [/^\w{2}$/, /^\d{5}$/]) == 3 


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.