allBefore method
Searches the string for the last occurrence of a pattern
and returns
everything before that occurrence.
Returns ''
if no occurrences were found.
Example:
'value=1'.allBefore('='); // 'value'
'i like turtles'.allBefore('like') // 'i '
Implementation
String allBefore(Pattern pattern) {
final matchIterator = pattern.allMatches(this!).iterator;
Match? match;
while (matchIterator.moveNext()) {
match = matchIterator.current;
}
if (match != null) return this!.substring(0, match.start);
return '';
}