how to replace pairs of tokens in a string?,doctest.testmod()