title: How to use a variable inside a RegEx pattern?
body: <p>Usage of this code is to show only the last four digits of an input.</p>
  
  <p>Here I want to replace this "(/.(?=.{4})/g, '*')" <strong>'4'</strong> with variable '<strong><em>mask</em></strong>' . Something like that.</p>
  
  <pre><code>x.value = x.value.replace(/.(?=.{+mask+})/g, '*');
  </code></pre>
  
  <p>Any suggestion plz</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction(mask) {
      var x = document.getElementById("cc");
      x.value = x.value.replace(/.(?=.{4})/g, '*');
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" id="cc" onkeyup="myFunction(4)" style="text-align:right"&gt;</code></pre>
  </div>
  </div>
  </p>