extractExpiryDate static method

String? extractExpiryDate(
  1. String text
)

Implementation

static String? extractExpiryDate(String text) {
  // Match MM/YY, MM/YYYY, MM-YY, etc.
  final regExp = RegExp(r'(\d{2})\s*[/-]\s*(\d{2,4})');
  final match = regExp.firstMatch(text);

  if (match != null) {
    String month = match.group(1)!;
    String year = match.group(2)!;

    // Validate month
    final monthNum = int.tryParse(month);
    if (monthNum == null || monthNum < 1 || monthNum > 12) return null;

    // Convert 2-digit year to 4-digit
    if (year.length == 2) {
      year = '20$year';
    }

    return '$month/$year';
  }
  return null;
}