diff --git a/dataclasses_json/stringcase.py b/dataclasses_json/stringcase.py index da0f546f..7bc18091 100644 --- a/dataclasses_json/stringcase.py +++ b/dataclasses_json/stringcase.py @@ -95,10 +95,14 @@ def snakecase(string): string = re.sub(r"[\-\.\s]", '_', str(string)) if not string: return string - return (uplowcase(string[0], 'low') - + re.sub(r"[A-Z0-9]", - lambda matched: '_' + uplowcase(matched.group(0), 'low'), - string[1:])) + return uplowcase( + '_'.join( + re.sub( + '([A-Z][a-z]+)', r' \1', + re.sub('([A-Z]+)', r' \1', string.replace('-', ' ')) + ).split() + ), 'low' + ) def spinalcase(string):