Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dart to remove all but digits from string using RegExp

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", "");
like image 822
Janaka Avatar asked Feb 03 '26 14:02

Janaka


1 Answers

You need to use

input.replaceAll(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.

like image 196
Wiktor Stribiżew Avatar answered Feb 06 '26 04:02

Wiktor Stribiżew