Skip to content

Instantly share code, notes, and snippets.

@iqbalmineraltown
Created February 26, 2020 08:03
Show Gist options
  • Save iqbalmineraltown/1874d687127471b4b8a2fed0fe9a2625 to your computer and use it in GitHub Desktop.
Save iqbalmineraltown/1874d687127471b4b8a2fed0fe9a2625 to your computer and use it in GitHub Desktop.
camelCase to snake_case without separating numbers
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