'Converts \'bad\' characters in a string to underscores so they can be used as Ansible groups'

def to_safe(self, word):

    if self.cloudforms_clean_group_keys:
        regex = '[^A-Za-z0-9\\_]'
        return re.sub(regex, '_', word.replace('    ', ''))
    else:
        return word
