there has to be some sort of predetermined known factor.
a specific word, or number of characters, or something.
your asking a wide question using a specific example without further details on the parameters.
the above coding example addresses the question as asked with the information provided.
if you want something more generic for the replacement, you'll need to provide more details.