Skip to content

ML Models & Algorithms

Boyer-Moore

In shortA fast exact string-search algorithm that compares a pattern from right to left and skips ahead after mismatches.

Updated 24 Oct 2026· 2 min read

Boyer-Moore is a classic algorithm for finding an exact pattern inside a longer piece of text. Published by Robert Boyer and J Strother Moore in 1977, it is one of the best-known string-search algorithms and is very fast in practice. In MLforSEO’s guide to fuzzy matching, it is the flagship example of exact matching, the strict end of the string-matching spectrum.

How it works

A naive search compares the pattern with the text one position at a time, left to right. Boyer-Moore lines the pattern up with the text but compares characters from the end of the pattern backwards. When it finds a mismatch it uses two precomputed tables to jump forward:

  • Bad character rule: if the mismatched text character does not appear in the pattern at all, the whole pattern can slide past it.
  • Good suffix rule: if part of the pattern already matched, the pattern shifts to the next place that matched part could reappear.

Because of these skips it often inspects only a fraction of the characters, and it tends to get faster as the pattern gets longer. It returns exact matches only: one wrong letter means no match.

How it’s used in SEO and marketing

  • Checking whether an exact brand name, product code or phrase appears in thousands of pages, titles or reviews.
  • Flagging exact keyword mentions in crawled content before a deeper semantic analysis.
  • Pre-filtering large datasets cheaply, so slower fuzzy or semantic methods only run on what is left.

In day-to-day SEO work you rarely implement it yourself. Fast substring search in programming languages, text editors and command-line tools uses Boyer-Moore or related ideas behind the scenes.

Example

You want every product description that mentions “GORE-TEX” across a 50,000-row export. An exact search finds “GORE-TEX” instantly but misses “Goretex” and “gore tex”. That is the point where MLforSEO suggests moving to distance-based matching such as Levenshtein, or phonetic matching, to catch the variants.

Limitations and things to watch

  • No tolerance for typos, spacing, plurals or synonyms.
  • No understanding of meaning, so “apple” the fruit and “Apple” the brand look the same once case is ignored.
  • Searching for many different patterns at once is better handled by multi-pattern algorithms such as Aho-Corasick.

Learn it on MLforSEO

Where Boyer-Moore shows up on MLforSEO

Sources and further reading

Other terms from ML Models & Algorithms

See all 55 ML Models & Algorithms terms →