title: Regex replace all commas with value
body: <p>I have a string that looks like this: "Doe, John, A" (lastname, firstname, middle initial).</p>
  
  <p>I'm trying to write a regular expression that converts the string into "Doe*John*A".</p>
  
  <p>However, I have to take into account all spaces for this string so "Doe    , John    , A" would still convert into "Doe*John*A". </p>
  
  <p>ALSO, the string "Doe John A" should convert into "Doe*John*A".</p>
  
  <p>I started writing this, but I think I'm stuck on the spaces &amp; the possibility of the user not supplying the commas.</p>
  
  <p>Here's what I have: </p>
  
  <pre><code>var myString = "John, Doe, A";
  var myOtherString = "John  Doe   A";
  
  
  var myFunction = function (aString) {
          aString = aString.replace(", ", "*");
          aString = aString.replace(", ", "*");
  
  return aString;
  
  };
  </code></pre>
  
  <p>These should both return <code>"Doe*John*A"</code>.</p>
  
  <p>I think I'm repeating myself too much in this function. I'm also not taking into account the possibility that no commas will be provided.</p>
  
  <p>Is there a better way to do this?</p>