A feature that auto-links matching keywords inside page text starts linking letters buried in the middle of unrelated words, not just genuine whole-word matches.
⚡ Quick Fix (TL;DR)
The Culprit: A plain substring search (JavaScript's indexOf, or an equivalent) matches a short term anywhere it appears as a sequence of characters, even mid-word. Confirmed directly: a dictionary term "URL" matched inside the unrelated word "curly," and "DOM" matched inside "domain" – both false positives from treating any character match as a hit, with no awareness of word boundaries.
The Fix: Match only whole-word occurrences using a word-boundary-anchored regular expression instead of plain substring search.
// Wrong — plain substring search, matches mid-word:
text.toLowerCase().indexOf(term.toLowerCase())
// Right — word-boundary regex, whole-word matches only:
var re = new RegExp("b" + term + "b", "i");
var match = re.exec(text); Was this helpful? Thanks for the feedback!
Tagged in :