Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Kabob - Case A String In Python

This is an adaptation of my snake _ case function (TKTKTK : link to snake _ case function when the site is moved). Haven't put a full test suite on it yet, but spot checking it seems to be fine.

python3
#!/usr/bin/env python3

import re 

def kabob(initial_string):
    
    return_string = initial_string.lower().replace(' ', '-')
    return_string = re.sub("'", '', return_string)
    return_string = re.sub('[^\w\.]', '-', return_string)
    return_string = re.sub('-+', '-', return_string)
    return_string = re.sub('-\.', '.', return_string)
    return_string = re.sub('\.-', '.', return_string)
    return_string = re.sub('^-+', '', return_string)
    
    return return_string

kabob_string = kabob('Kabob Case A String In Python')

print(kabob_string)