Reading Time: 1 minutes
camelCase to underscore_separated_lowercase in Python
Write a Regular Expression in Python to convert camelCase to underscore_separated_lowercase words.
import re sourceString = 'randomCamelCaseVariableOne randomCamelCaseVariableTwo' print( re.sub('([a-z]+)([A-Z])', r'\1_\2', sourceString).lower() ) # random_camel_case_variable_one random_camel_case_variable_two
To learn more about Regular Expressions in Python, click here.