lastPartition method

List<String> lastPartition(
  1. Pattern pattern, [
  2. int? start
])

Splits the string at the last occurrence of pattern.

Returns a list containing the part before the separator, the separator itself, and the part after the separator. If the pattern is not found, return a list two empty strings followed by this string.

Implementation

List<String> lastPartition(Pattern pattern, [int? start]) {
  final i = lastIndexOf(pattern, start);
  if (i == -1) return ['', '', this];
  final j = pattern is String
      ? i + pattern.length
      : pattern.matchAsPrefix(this, i)!.end;
  return [substring(0, i), substring(i, j), substring(j)];
}