replaceFirst function

String? replaceFirst(
  1. String? value,
  2. String regExp,
  3. String replacement, [
  4. int startIndex = 0,
])

Replaces the first substring in value that matches regExp with replacement.

  • Starts searching at startIndex.
  • Returns null if value is null.

Implementation

String? replaceFirst(String? value, String regExp, String replacement, [int startIndex = 0]) {
  if (value == null) return null;
  final regex = RegExp(regExp);
  return value.replaceFirst(regex, replacement, startIndex);
}