How to use dart to remove all but digits from string using RegExp
1,371
You need to use
input.replaceAll(new RegExp(r"\D"), "");
See the replaceAll
method signature: String replaceAll (Pattern from, String replace)
, from
must be a Pattern class instance.
Note that r"\D"
, a raw string literal, is a more convenient way to define regular expressions, since regular string literals, like "\\D"
, require double escaping of backslashes that form regex escapes.
Author by
Janaka
Updated on December 24, 2022Comments
-
Janaka over 1 year
Can someone show me how to use dart language to remove all but digits from a string?
Tried this but it does not seems to work
input.replaceAll("\\D", "");