Created
October 6, 2021 16:51
-
-
Save 8dcc/d61078075b02e787c758cdf5791cecb3 to your computer and use it in GitHub Desktop.
Convert string to camel case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def to_camel_case(text): | |
| result = "" | |
| first = True | |
| if ("-" in text) or ("_" in text): | |
| for word in re.findall(r"[a-zA-Z0-9]+", text): | |
| if first: | |
| result = result + word | |
| first = False | |
| else: | |
| result = result + word.lower().capitalize() | |
| return result | |
| else: | |
| return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment