import re


def _str_replace(mystring, rd):
    """replaces a value based on a key/value pair where the
    key is the text to replace and the value is the new value.

    The find/replace is case insensitive.

    """
    patternDict = {}
    myDict = {}
    for key,value in rd.items():
        pattern = re.compile(re.escape(key), re.IGNORECASE)
        patternDict[value] = pattern
    for key in patternDict:
        regex_obj = patternDict[key]
        mystring = regex_obj.sub(key, mystring)
    return mystring