You don't need the prev.contains check, since the criteria query will never return duplicate tags.
Also, is this isSearchTermBeginningOfWord any different than just doing MatchMode.START a few lines back?