How to replace certain strings (variables) with st-annotated-text

Hi !
I have a txt and a list of strings which I want to replace in the text with a certain labels using the st-annotated-text component. How can I replace only the strings I want and leaving the rest unchanged?
My input is a variable so I can’t do it this is way :
annotated_text(
"This ",
(“is”, “verb”, “#8ef”),
" some ",
(“annotated”, “adj”, “#faa”),
(“text”, “noun”, “#afa”),
" for those of ",
(“you”, “pronoun”, “#fea”),
" who ",
(“like”, “verb”, “#8ef”),
" this sort of ",
(“thing”, “noun”, “#afa”),
)

For example I have the strings “My sister loves him” or “My friend loves him” and I would like to replace only “him” with a pronoun label"