normalizeCodeLikeTokens function

String normalizeCodeLikeTokens(
  1. String line
)

Normalizes mixed alphanumeric code-like tokens without touching prose.

This uppercases alphabetic code segments, converts digit-lookalike letters at the start of digit runs, and restores hyphen separators in simple compound IDs such as ORD+20250615+0042.

Implementation

String normalizeCodeLikeTokens(String line) {
  if (!hasCodeLikeToken(line)) {
    return line;
  }

  return line.replaceAllMapped(
    RegExp(r'[A-Za-z0-9][A-Za-z0-9+\-/:]*[A-Za-z0-9]'),
    (Match match) {
      final String token = match.group(0)!;
      if (!_looksNormalizableCodeToken(token)) {
        return token;
      }
      return _normalizeCodeLikeToken(token);
    },
  );
}