betweenResultLast method

  1. @useResult
BetweenResult? betweenResultLast(
  1. String start,
  2. String end, {
  3. bool endOptional = true,
  4. bool trim = true,
})

Returns a BetweenResult like betweenResult but searches from the end using start and end delimiters.

When endOptional is true (default) and end is not found, returns content after the last start. When trim is true (default), results are trimmed.

Implementation

@useResult
BetweenResult? betweenResultLast(
  String start,
  String end, {
  bool endOptional = true,
  bool trim = true,
}) {
  if (isEmpty) {
    return null;
  }

  final String found = betweenLast(start, end, endOptional: endOptional, trim: trim);
  if (found.isEmpty) {
    return null;
  }

  final String removed = replaceFirst(start + found + end, '');
  final String remaining = trim ? removed.replaceAll(RegExp(r'\s+'), ' ').trim() : removed;

  return BetweenResult(found, remaining);
}