def regex_replace(value='', pattern='', replacement='', ignorecase=False):
 value = to_text(value, errors='surrogate_or_strict', nonstring='simplerepr')
 if ignorecase:
  flags = re.I
 else:
  flags = 0
 _re = re.compile(pattern, flags=flags)
 return _re.sub(replacement, value)

def regex_replace ( value = '' , pattern = '' , replacement = '' , ignorecase = False ) : value = to_text ( value , errors = 'surrogate_or_strict' , nonstring = 'simplerepr' ) if ignorecase : flags = re . I else : flags = 0 _re = re . compile ( pattern , flags = flags ) return _re . sub ( replacement , value )
perform a re .