replacingOccurrences method

String replacingOccurrences({
  1. required String matchingPattern,
  2. required String replacementProvider(
    1. String
    ),
})

Replaces occurrences of the matching pattern in the string with the provided replacement function. Uses a regular expression to find matches and applies the replacement function to each match.

Implementation

String replacingOccurrences({
  required String matchingPattern,
  required String Function(String) replacementProvider,
}) {
  final regExp = RegExp(matchingPattern);
  return replaceAllMapped(
    regExp,
    (match) => replacementProvider(match.group(0)!),
  );
}