extractDigits method

String extractDigits()

Extracts all numerical digits from the string and returns them as a new string.

All non-digit characters (including letters, symbols, and spaces) are removed.

@returns A new string containing only the digits.

Example:

final messy = 'Price: $12.99 USD';
print(messy.extractDigits()); // "1299"

Implementation

String extractDigits() => replaceAll(RegExp(r'\D'), '');