title: How to write a RegEx to format a CC number
body: <p>I've almost got this function working as desired. I'm passing a string that will have certain characters replaced(12 numbers in this first case) with dashes to help hide the CC number, while keeping the last four #'s of the string. I could use some help in replacing a string that's already got certain characters in it.</p>
  <p>This function works well if I pass in a string like '9876 5432 1098 1005', but I also need to test a string if it already has characters to hide the CC numbers, like this '************2006'. If I can solve for these two cases, that would be amazing. Thanks in advance for the help :)</p>
  <pre><code>export const formatCard = (acct: string, hide = false): string =&gt; {
    const regExFormula = /\b(?:\d{4}[ -]?){3}(?=\d{4}\b)/gm;
    const subst = `---- ---- ---- `;
  
    if (hide === true) {
      return acct.replace(regExFormula, subst);
    }
    return acct;
  };
  </code></pre>