Reputation: 313
String text = "replace all characters" --> 22 characters
text.replaceAll(RegExp('.'), '*');
// result -> ********************** --> 22 characters
In this way, all characters change. How do I exclude the space character.
// I want it this
// result -> ******* *** ********** -> Characters 8 and 13 are empty.
Upvotes: 1
Views: 1086
Reputation: 31219
What you want is a negative match:
void main() {
String text = "replace all characters";
print(text.replaceAll(RegExp('[^ ]'), '*'));
// ******* *** **********
}
[^ ]
Will match any character that is not space.
Upvotes: 5