splitBefore method

String splitBefore(
  1. Pattern pattern
)

Splits from a pattern and returns String before that

Implementation

String splitBefore(Pattern pattern) {
  ArgumentError.checkNotNull(pattern, 'pattern');
  var matchIterator = pattern.allMatches(validate()).iterator;

  Match? match;
  while (matchIterator.moveNext()) {
    match = matchIterator.current;
  }

  if (match != null) {
    return validate().substring(0, match.start);
  }
  return '';
}