NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Kabob-Case A String In Python

August 2021

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.

#!/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')

═══ § ═══