words function

List<String> words({
  1. required String string,
  2. RegExp? pattern,
  3. bool guard = false,
})

Splits String into an array of its words.

Implementation

List<String> words(
    {required String string, RegExp? pattern, bool guard = false}) {
  pattern = guard ? null : pattern;

  if (pattern == null) {
    return helpers.hasUnicodeWord(string)
        ? helpers.unicodeWords(string)
        : helpers.asciiWords(string);
  }
  Iterable<Match> matches = pattern.allMatches(string);
  List<String> result = [];
  for (Match match in matches) {
    result.add(match[0]!);
  }
  return result;
}