import re


def _replace_string_in_file(source_file, new_file, repldict):
    """Find strings within a file and creates a new one with strings replaced.

    Keyword arguments:
    source_file -- Source file, with the string(s) to be replaced
    new_file -- File name that will have the content of the source file with
        the string(s) replaced.
    repldict -- Dictionary containing one or more strings to be replaced. The
        keys will be the matching strings and the values will be the replacing
        strings. I.e.
            repldict = {
                'old string1': 'new string1',
                'old string2': 'new string2', ...
            }
    """
    pfile_path = source_file
    def _replfunc(match):  # Replacing function
        return repldict[match.group(0)]
    regex = re.compile('|'.join(re.escape(i) for i in repldict))
    with open(pfile_path) as fin:
        with open(new_file, 'w') as fout:
            for line in fin:
                fout.write(regex.sub(_replfunc, line))