Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart: Replace every letter in a string with an asterix using regxp

Tags:

dart

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.

like image 787
SSS Avatar asked Sep 23 '17 16:09

SSS


1 Answers

var regex = new RegExp(r'[a-zA-Z]')

var replaced = 'some string / with $ other = chars'.replaceAll(regex, '*');

DartPad example

like image 174
Günter Zöchbauer Avatar answered Oct 31 '22 18:10

Günter Zöchbauer