How to extract number only from string in flutter?

Question

Asked by Zero L on April 24, 2020 (source).

Lets say that I have a string:

a="23questions";
b="2questions3";

Now I need to parse 23 from both string. How do I extract that number or any number from a string value?

Answer

Question answered by Hashir B (source).

The following code can extract the number:

aStr = a.replaceAll(new RegExp(r'[^0-9]'),''); // '23'

You can parse it into integer using:

aInt = int.parse(aStr);
DART FLUTTER
SHARE: