def replaceText(infile, sub={}, outfile=None):
    """replaceText(infile,[sub,outfile]) --> replace text {old:new} in a file
    this function uses regular expressions, if a pattern is given as old text
    Note: this may fail if order of substitution is important"""
    if outfile == None:
        outfile = infile
    input = open(infile, 'r')
    filestring = input.read()
    input.close()
    import re
    for old, new in list(sub.items()):
        filestring = re.compile(old).sub(new, filestring)
    output = open(outfile, 'w')
    output.write(filestring)
    output.close()
    return
