This can be done with <code>re</code> module compiled regex object and python file IO.