Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-11-02 19:28:05 +02:00
parent 0ab4b3dbc5
commit 0a2f7993f7
24 changed files with 63 additions and 51 deletions

View File

@ -5,7 +5,9 @@ tags: string,regexp,intermediate
Converts a string to kebab case.
- Break the string into words and combine them adding `-` as a separator, using a regexp.
- 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.
```py
from re import sub
@ -20,6 +22,7 @@ def kebab(s):
```py
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"
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'
```