Boyer–Moore search

Find ABRA in AXRAABRA. On the first try, RA already matches. See why those two letters let the pattern move three places.

Start at the right edge of the pattern. When two letters match, compare the next pair to the left.

Both rules give a safe shift. Use the larger distance.

Letters are compared from right to left. With repeated letters this version can use up to n × m comparisons for n text letters and m pattern letters.