title: How to preserve character case using string.replace()?
body: <p>I am attempting to write a function that will replace all of the vowels in a string with another arbitrary vowel which is selected by an end user. So far, I have been able to write a function that will replace all of the vowels regardless of case, but I would like to be able to preserve the case during <code>replace()</code>.</p>
  
  <p>Here is an example of what I am doing right now.</p>
  
  <pre><code>
  var selectedVowel = "a";
  var vowels = /[aeiouAEIOU]/gi;
  
  function rep(string){
  let newString = string.replace(vowels, selectedVowel);
  return newString;
  }
  
  rep("FooBar Exe. unIt");
  // returns "FaaBar axe. anat"
  // Intended output should return "FaaBar Axe. anAt"
  </code></pre>
  
  <p>I have tried using Regular Expressions to modify the search criteria for <code>replace()</code> and <code>selectedVowel</code>, but I can't figure out how to use the right regex characters to achieve that end.</p>
  
  <p>I have also looked into methods that use <code>split()</code> to replace the first letter of a word, but this method seems to be limited to the string's indexes, which are not known at the time of the function call.</p>
  
  <p>Any suggestions?</p>