import re
def convert(name):
return re.sub(r'([A-Z]*)([A-Z][a-z]+)', lambda x: (x.group(1) + '_' if x.group(1) else '') + x.group(2) + '_', name).rstrip('_').lower()
def camel_to_snake(name):
return re.sub(r"(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])", '_', name).lower()
print convert('CamelCase')
print convert('HTTP')
print convert('HTTPRequest')
print convert('SecureHTTPRequest')
print convert('SecureHTTP')
print camel_to_snake('CamelCase')
print camel_to_snake('HTTP')
print camel_to_snake('HTTPRequest')
print camel_to_snake('SecureHTTPRequest')
print camel_to_snake('SecureHTTP')
aW1wb3J0IHJlCgpkZWYgY29udmVydChuYW1lKToKICAgIHJldHVybiByZS5zdWIocicoW0EtWl0qKShbQS1aXVthLXpdKyknLCBsYW1iZGEgeDogKHguZ3JvdXAoMSkgKyAnXycgaWYgeC5ncm91cCgxKSBlbHNlICcnKSArIHguZ3JvdXAoMikgKyAnXycsIG5hbWUpLnJzdHJpcCgnXycpLmxvd2VyKCkKCmRlZiBjYW1lbF90b19zbmFrZShuYW1lKToKICAgIHJldHVybiByZS5zdWIociIoPzw9W2Etel0pKD89W0EtWl0pfCg/PD1bQS1aXSkoPz1bQS1aXVthLXpdKSIsICdfJywgbmFtZSkubG93ZXIoKQoKcHJpbnQgY29udmVydCgnQ2FtZWxDYXNlJykKcHJpbnQgY29udmVydCgnSFRUUCcpCnByaW50IGNvbnZlcnQoJ0hUVFBSZXF1ZXN0JykKcHJpbnQgY29udmVydCgnU2VjdXJlSFRUUFJlcXVlc3QnKQpwcmludCBjb252ZXJ0KCdTZWN1cmVIVFRQJykKCnByaW50IGNhbWVsX3RvX3NuYWtlKCdDYW1lbENhc2UnKQpwcmludCBjYW1lbF90b19zbmFrZSgnSFRUUCcpCnByaW50IGNhbWVsX3RvX3NuYWtlKCdIVFRQUmVxdWVzdCcpCnByaW50IGNhbWVsX3RvX3NuYWtlKCdTZWN1cmVIVFRQUmVxdWVzdCcpCnByaW50IGNhbWVsX3RvX3NuYWtlKCdTZWN1cmVIVFRQJyk=