I think that is impossible.  For example, (‘Er’) will sometimes be a whole word and sometimes be part of Ermittler.   If your function only sees ‘Er’ or ‘17’, it can’t know which is true.
On the other hand, if your function sees the original text as well, it can easily detect whether it is a whole word or not.   Different tokenizers will split words in different ways, but any function that sees both the whole text and the tokenized text could comment on it.
Why do you need such a function?