Created
February 26, 2020 08:03
-
-
Save iqbalmineraltown/1874d687127471b4b8a2fed0fe9a2625 to your computer and use it in GitHub Desktop.
camelCase to snake_case without separating numbers
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
String camelCaseToSnakeCase(String str) { | |
final RegExp uppercases = RegExp('[A-Z]+'); | |
return str | |
.replaceAllMapped(uppercases, (match) => ' ${match.group(0)}') | |
.trim() | |
.split(' ').map((s) => s.toLowerCase()).join('_'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment