I was trying to replace every letter in a string with an asterix using Dart and am having some difficulty. In Javascript it is:
'test'.replace(/./g, '*');
So in Dart, I tried the following:
'test'.replaceAll(new RegExp(r'/.'), '*');
'test'.replaceAll(new RegExp(r'\/.'), '*');
'test'.replaceAll(new RegExp(r'/./'), '*');
'test'.replaceAll(new RegExp(r'\/.\/'), '*');
I obviously don't quite understand how this should work as cannot seem to make this work.
Can anyone advise the correct way to do this with a short explanation?
Thanks.
var regex = new RegExp(r'[a-zA-Z]')
var replaced = 'some string / with $ other = chars'.replaceAll(regex, '*');
DartPad example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With