def _clean_string(str, regex='(^[^a-zA-Z\\._]+)|([^a-zA-Z\\._0-9]+)', replace='_'):
 regex = re.compile(regex)
 if str[0].isdigit():
  str = (replace + str)
 return regex.sub(replace, str)

def _clean_string ( str , regex = '(^[^a-zA-Z\\._]+)|([^a-zA-Z\\._0-9]+)' , replace = '_' ) : regex = re . compile ( regex ) if str [ 0 ] . isdigit ( ) : str = ( replace + str ) return regex . sub ( replace , str )
replaces a string that matches the regex with the replacement .