def _escape_for_regex(text):
 regex = re.escape(text)
 regex = regex.replace('\\\\', '\\\\\\')
 regex = regex.replace('\\$', '\\\\\\$')
 regex = regex.replace("\\'", "'")
 return regex

def _escape_for_regex ( text ) : regex = re . escape ( text ) regex = regex . replace ( '\\\\' , '\\\\\\' ) regex = regex . replace ( '\\$' , '\\\\\\$' ) regex = regex . replace ( "\\'" , "'" ) return regex
escape text to allow literal matching using egrep .