words method
Splits the string into its constituent words.
Handles spaces, hyphens, underscores, and camelCase/PascalCase boundaries. This is the basis for the case-conversion helpers below.
Example:
'helloWorld'.words(); // ['hello', 'World']
'foo_bar-baz'.words(); // ['foo', 'bar', 'baz']
Implementation
List<String> words() => replaceAllMapped(
RegExp('([a-z0-9])([A-Z])'),
(Match m) => '${m[1]} ${m[2]}',
)
.split(RegExp(r'[\s_-]+'))
.where((String word) => word.isNotEmpty)
.toList();