onlyLetters property

String onlyLetters

Returns only the Latin OR Greek characters from the String.

Example

String foo = '4*%^55/σοφ4e5523ια';
String onlyL1 = foo.onlyLetters; // returns 'σοφια'
String foo2 = '4*%^55/es4e5523nt1is';
String onlyL2 = foo2.onlyLetters; // returns 'esentis'

Implementation

String get onlyLetters {
  if (this.isBlank) {
    return this;
  }
  // ignore: unnecessary_raw_strings
  var regex = RegExp(r'([^α-ωΑ-ΩίϊΐόάέύϋΰήώΊΪΌΆΈΎΫΉΏa-zA-Z\s]+)');
  return this.replaceAll(regex, '');
}