removeBetweenAll method

String removeBetweenAll(
  1. String start,
  2. String end, {
  3. bool inclusive = true,
})

Removes all content between start and end delimiters.

If inclusive is true (default), removes the delimiters as well.

Implementation

String removeBetweenAll(String start, String end, {bool inclusive = true}) {
  if (start.isEmpty) return this;
  if (this == start + end && inclusive) return '';
  final String found = between(start, end, endOptional: false);
  if (found.isEmpty && !contains(start + end)) {
    if (contains(start) && contains(end) && indexOf(start) < indexOf(end)) {
      if (inclusive && this == start + end) return '';
    } else {
      return this;
    }
  }
  final String pattern = inclusive ? (start + found + end) : found;
  if (pattern.isEmpty && !inclusive) return this;
  return replaceAll(pattern, '');
}