replaceFirstAndFormat method

String replaceFirstAndFormat(
  1. String text,
  2. Pattern pattern,
  3. String format
)

Implementation

String replaceFirstAndFormat(String text, Pattern pattern, String format) {
  return text.replaceFirstMapped(pattern, (match) {
    return format.replaceFirstMapped(firstGroupPattern, (placeholderMatch) {
      final groupNumber = int.parse(placeholderMatch.group(1)!);
      return match.group(groupNumber) ?? '';
    });
  });
}