title: Match regex using array
body: <p>I made this in C++ and I wanted to convert to JavaScript:</p>
  
  <pre><code>foreach (QString pattern, extensions) {
      regex.setPattern(QString("\\.%1").arg(pattern));
      regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
  
      QRegularExpressionMatch match = regex.match(filename);
  
      if (! match.hasMatch()) continue;
  
      return pattern;
  }
  </code></pre>
  
  <p>It means that foreach <code>extensions</code> (that is an array of extensions) as <code>pattern</code> create a pattern with that to be like: <code>\\.png</code> (for example).
  If there's a match it will return the found extension.</p>
  
  <p>I tried to create exactly how I did in C++ but I don't know how to concatenate the returned string from the array to match </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>const filename = 'example.wutt'
  const extensions = ['wutt', 'xnss']
  
  extensions.forEach(pattern =&gt; {
    const match = filename.match(`\\.${pattern}`)
    console.log(match)
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>It does work but it's not case-insensitive as I can't put the <code>i</code> flag.</p>
  
  <p>How can I do that (and if there's a solution using ES6)?</p>