def escapestr(text, ampm):
 new_text = re.escape(text)
 new_text = new_text.replace(re.escape(ampm), ampm)
 new_text = new_text.replace('\\%', '%')
 new_text = new_text.replace('\\:', ':')
 new_text = new_text.replace('\\?', '?')
 return new_text

def escapestr ( text , ampm ) : new_text = re . escape ( text ) new_text = new_text . replace ( re . escape ( ampm ) , ampm ) new_text = new_text . replace ( '\\%' , '%' ) new_text = new_text . replace ( '\\:' , ':' ) new_text = new_text . replace ( '\\?' , '?' ) return new_text
escape text to deal with possible locale values that have regex syntax while allowing regex syntax used for comparison .