Skip to content

Instantly share code, notes, and snippets.

@8dcc
Created October 6, 2021 16:51
Show Gist options
  • Select an option

  • Save 8dcc/d61078075b02e787c758cdf5791cecb3 to your computer and use it in GitHub Desktop.

Select an option

Save 8dcc/d61078075b02e787c758cdf5791cecb3 to your computer and use it in GitHub Desktop.
Convert string to camel case
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