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