lettersOnly method

String lettersOnly()

Extracts only ASCII letter characters (A-Z, a-z) from this string.

Removes all characters that are not ASCII letters using a regex replacement. Note: This is ASCII-only; Unicode letters like 'é' or '你' are removed.

Returns: A new string containing only ASCII letters, or empty string if none found.

Example:

'Hello123World!'.lettersOnly(); // 'HelloWorld'
'abc-def'.lettersOnly(); // 'abcdef'
'123'.lettersOnly(); // ''
'café'.lettersOnly(); // 'caf' (é removed)

Implementation

String lettersOnly() {
  if (isEmpty) return '';
  return replaceAll(RegExp(r'[^A-Za-z]'), '');
}