onlyNumbers property
String
onlyNumbers
Returns only the numbers from the String
.
Example
String foo = '4*%^55/es4e5523nt1is';
String onyNumbers = foo.onlyNumbers; // returns '455455231'
Implementation
String get onlyNumbers {
if (this.isBlank) {
return this;
}
// ignore: unnecessary_raw_strings
var regex = RegExp(r'([^0-9]+)');
return this.replaceAll(regex, '');
}