Template literal inside of the RegEx : <p>I tried to place a template literal inside of a RegEx, and it didn't work. I then made a variable <code>regex</code> which holds my RegEx, but it still not giving me the desired result.</p>

<p>However if I <code>console.log(regex)</code> individually, I do receive the desired RegEx, such as <code>/.+?(?=location)/i</code>, <code>/.+?(?=date)/i</code> and so on, but once I place <code>regex</code> inside the <code>.replace</code> it appears not to be working</p>

<pre><code>function validate (data) {
  let testArr = Object.keys(data);
  errorMessages.forEach((elem, i) =&gt; {
    const regex = `/.+?(?=${elem.value})/i`;
    const a = testArr[i].replace(regex, '');
    })
  }
</code></pre>
