Last active
September 27, 2018 06:59
-
-
Save PattoMotto/cb1b8cea01e0a407d30dd725f456df74 to your computer and use it in GitHub Desktop.
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
# credit https://dev.to/rrampage/snake-case-to-camel-case-and-back-using-regular-expressions-and-python-m9j | |
# credit https://stackoverflow.com/a/3847369 | |
import re | |
REG = r"(.+?)([A-Z])" | |
def camel(match): | |
return match.group(1).lower() + match.group(2)[0].upper() + match.group(2)[1:].lower() | |
lowerFirstChar = lambda s: s[:1].lower() + s[1:] if s else '' | |
words = """MyClass | |
MyClassFactory | |
MyClassFactoryBuilder | |
MyClassFactoryBuilderImpl | |
myInstance | |
myInstance2 | |
abc | |
patternMatcher | |
Hello""".splitlines() | |
results = [re.sub(REG, camel, lowerFirstChar(w.strip()), 0) 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