From: Nate Murray Date: 2010-10-27T23:16:47+09:00 Subject: Re: Boyer-Moore string search algorithm in ruby Hey all, I realize this thread is a few years old, but I just wrote a Ruby library for doing Boyer-Moore string searching which you can find here: http://www.xcombinator.com/2010/10/27/boyer-moore-string-search-algorithm-in-ruby/ . It's basically a port of the current wikipedia c-code, but it also supports searching token arrays and the tokens can be regular expressions. For instance: Usage: BoyerMoore.search(haystack, needle) # returns index of needle or nil Examples: BoyerMoore.search("ANPANMAN", "ANP") # => 0 BoyerMoore.search("ANPANMAN", "ANPXX") # => nil BoyerMoore.search(["", "hi", ""], ["hi"]) # => 1 BoyerMoore.search(["bam", "foo", "bar"], ["foo", "bar"]) # => 1 BoyerMoore.search(["bam", "bar", "baz"], ["foo"]) # => nil BoyerMoore.search(["Sing", "99", "Luftballon"], [/\d+/]) == 1 BoyerMoore.search(["Nate Murray", "5 Pine Street", "Los Angeles", "CA", "90210"], [/^\w{2}$/, /^\d{5}$/]) == 3 The regexp matching is fairly slow, so be wary of using it. Hope this helps someone! Nate -- Posted via http://www.ruby-forum.com/.