removeNumbers method Null safety

String? removeNumbers()

Removes only the numbers from the String.

Example 1

String foo = 'es4e5523nt1is';
String noNumbers = foo.removeNumbers(); // returns 'esentis'

Example 2

String foo = '1244e*s*4e*5523n*t*1i*s';
String noNumbers = foo.removeNumbers(); // returns 'e*s*e*n*t*i*s'

Implementation

String? removeNumbers() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return this;
  }
  var regex = RegExp(r'(\d+)');
  return this!.replaceAll(regex, '');
}