파이썬 camel case()

1 개요[ | ]

Python camel_case()
파이썬 camel_case()
import re
def camel_case(s):
    s = re.sub(r"[-_ ]+","",re.sub(r'([A-Z])([a-z])',r"_\1\2",s).title())
    if s == "": return ""
    return s[0].lower() + s[1:]

samples = ['FooBar', 'fooBar', 'foo_bar', 'Foo Bar', 'foo bar', 'foo-bar', 'FOO_BAR', 'FOO-BAR', 'Foobar', 'FOOBAR', 'F', ''];
for sample in samples:
    print( '[' + sample + '] → [' + camel_case(sample) + ']' )
# [FooBar] → [fooBar]
# [fooBar] → [fooBar]
# [foo_bar] → [fooBar]
# [Foo Bar] → [fooBar]
# [foo bar] → [fooBar]
# [foo-bar] → [fooBar]
# [FOO_BAR] → [fooBar]
# [FOO-BAR] → [fooBar]
# [Foobar] → [foobar]
# [FOOBAR] → [foobar]
# [F] → [f]
# [] → []

2 같이 보기[ | ]

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