파이썬 kebab_case()

1 개요[ | ]

Python kebab_case()
파이썬 kebab_case()
import re
def kebab_case(s):
    return re.sub(r"[-_ ]+","-",re.sub(r"^-","",re.sub(r"([A-Z])", r"-\1",s))).lower()

samples = ['foo_bar', 'Foo Bar', 'FooBar', 'fooBar', 'foo bar', 'foo-bar', 'Foobar', 'FOOBAR']
for sample in samples:
    print(sample, '→', kebab_case(sample))
# foo_bar → foo-bar
# Foo Bar → foo-bar
# FooBar → foo-bar
# fooBar → foo-bar
# foo bar → foo-bar
# foo-bar → foo-bar
# Foobar → foobar
# FOOBAR → f-o-o-b-a-r

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}