import re "_".join(l.lower() for l in re.findall('[AZ][^AZ]*', 'ThisIsAGoodExample'))
EDIT: Actually, this only works if the first letter is uppercase. Otherwise, this (taken from here ) does the right thing:
def convert(name): s1 = re.sub('(.)([AZ][az]+)', r'\1_\2', name) return re.sub('([a-z0-9])([AZ])', r'\1_\2', s1).lower()
xubuntix
source share