In my case all the strings are single-worded and the trailing whitespaces from the strings need to be removed, e.g., 'hello '→ 'hello'; 'hello '→ 'hello'.
One approach could be using split, i.e,
{% if ' ' in word %}
{% set word = word.split(' ')[0] %}
{% endif %}
This works since the strings are one-worded. I am quite sure there must be a better approach.