Created
September 26, 2018 10:49
-
-
Save PattoMotto/d0d9cfd8aba5e0a9743a723228fb760d to your computer and use it in GitHub Desktop.
This file contains 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
# credit https://dev.to/rrampage/snake-case-to-camel-case-and-back-using-regular-expressions-and-python-m9j | |
import re | |
REG = r"(.+?)([A-Z])" | |
def snake(match): | |
return match.group(1).lower() + "-" + match.group(2).lower() | |
words = """MyClass | |
MyClassFactory | |
MyClassFactoryBuilder | |
MyClassFactoryBuilderImpl | |
myInstance | |
myInstance2 | |
abc | |
patternMatcher | |
Hello""".splitlines() | |
results = [re.sub(REG, snake, w.strip(), 0).lower() for w in words] | |
[print(w) for w in results] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment