shouldn't you use ``startpos + highlight_offset + word.length`` to start matching only at the end of the occurrence we just found ?