factored out grep_word from expand_query