findName method

String? findName(
  1. String text
)

Implementation

String? findName(String text) {
  RegExp nameRegex = RegExp(r'@@\s+([A-Za-z\s]+)\s+@@');
  Iterable<RegExpMatch> matches = nameRegex.allMatches(text);

  String? name;
  if (matches.isNotEmpty) {
    Match match = matches.last;
    name = match.group(1);
    // Trim leading and trailing spaces if needed
    name = name?.trim();
    return name;
  }
  return null;
}