In a template hook or template post render event, you can use str_replace or preg_replace to do replacements. The first is the more simpler of the two. Simple find a string and replace it with another string. preg_replace is much more complicated as you search for a regular expression.
Plenty of docs online for those.