I have a string that looks like this: \"Doe, John, A\" (lastname, firstname, middle initial).
I\'m trying to write a regular expression that converts the string into \"D
String.replace only replaces the first occurence. To replace them all, add the "g" flag for "global". You can also use character groups and the +operator (one or more) to match chains of characters:
aString.replace("[,\s]+", "*", "g");
This will replace all chains of commas and whitespaces with a *
.