def _sed_esc(string, escape_all=False):
 special_chars = '^.[$()|*+?{'
 string = string.replace("'", '\'"\'"\'').replace('/', '\\/')
 if (escape_all is True):
  for char in special_chars:
   string = string.replace(char, ('\\' + char))
 return string

def _sed_esc ( string , escape_all = False ) : special_chars = '^.[$()|*+?{' string = string . replace ( "'" , '\'"\'"\'' ) . replace ( '/' , '\\/' ) if ( escape_all is True ) : for char in special_chars : string = string . replace ( char , ( '\\' + char ) ) return string
escape single quotes and forward slashes .