How to get only one word out of the repetitive word series for exanple XYZ FROM XYZ XYZ XYZ or XYZ,XYZ,XYZ or XYZ?XYZ?XYZ.
try a regular expression:
\b -> word boundary
(\w+) finds a group of letters, digits and underscores = the searched word
(?=\W\1\b) checks if the previous word is repeated without adding it to the result
\W is any other character besides letters, digits and underscores
\1 the previous word