Telegram Group & Telegram Channel
Converts a string to kebab case.

👉Use re.sub() to replace any - or _ with a space, using the regexp r"(_|-)+".

👉Use re.sub() to match all words in the string, str.lower() to lowercase them.

👉Finally, use str.join() to combine all word using - as the separator.

CODE:

from re import sub

def kebab(s):
return '-'.join(
sub(r"(\s|_|-)+"," ",
sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
lambda mo: ' ' + mo.group(0).lower(), s)).split())

Examples

kebab('camelCase') # 'camel-case'

kebab('some text') # 'some-text'

kebab('some-mixed_string With spaces_underscores-and-hyphens')
# 'some-mixed-string-with-spaces-underscores-and-hyphens'

kebab('AllThe-small Things') # 'all-the-small-things'

Share and Support
@Python_Codes



tg-me.com/python_codes/168
Create:
Last Update:

Converts a string to kebab case.

👉Use re.sub() to replace any - or _ with a space, using the regexp r"(_|-)+".

👉Use re.sub() to match all words in the string, str.lower() to lowercase them.

👉Finally, use str.join() to combine all word using - as the separator.

CODE:

from re import sub

def kebab(s):
return '-'.join(
sub(r"(\s|_|-)+"," ",
sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
lambda mo: ' ' + mo.group(0).lower(), s)).split())

Examples

kebab('camelCase') # 'camel-case'

kebab('some text') # 'some-text'

kebab('some-mixed_string With spaces_underscores-and-hyphens')
# 'some-mixed-string-with-spaces-underscores-and-hyphens'

kebab('AllThe-small Things') # 'all-the-small-things'

Share and Support
@Python_Codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/168

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

Python Codes from ru


Telegram Python Codes
FROM USA