def change_case(s, separator='<STR_LIT:->'):
s = s.strip()<EOL>no_spaces = re.sub('<STR_LIT:U+0020>', '<STR_LIT:_>', s)<EOL>add_underscores = re.sub('<STR_LIT>', r'<STR_LIT>', no_spaces)<EOL>lowercase = re.sub('<STR_LIT>', r'<STR_LIT>', add_underscores).lower()<EOL>return re.sub('<STR_LIT>', separator, lowercase)<EOL>
Changes the case to snake/kebab case depending on the separator.

    As regexes can be confusing, I'll just go through this line by line as an
    example with the following string: ' Foo2Boo_barBaz bat'

    1. Remove whitespaces from beginning/end. => 'Foo2Boo_barBaz bat-rat'
    2. Replace remaining spaces with underscores => 'Foo2Boo_barBaz_bat-rat'
    3. Add underscores before capital letters => 'Foo2_Boo_bar_Baz_bat-rat'
    4. Replace capital with lowercase => 'foo2_boo_bar_baz_bat-rat'
    5. Underscores & hyphens become the separator => 'foo2-boo-bar-baz-bat-rat'

    Args:
        s (str): The original string.
        separator: The separator you want to use (default '-' for kebab case).

    Returns:
        A snake_case or kebab-case (depending on separator)