I have two strings in camel case as follows
s1 = JavaBeans s2 = JavaStrutsSwing
How do I use a python function to convert the camel case of these strings into snake case?
Code for converting camel case to snake case is given below
import re def convert(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() print convert('JavaBeans') print convert('JavaStrutsSwing')
OUTPUT
java_beans java_struts_swing
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more