title: Techniques for getting values of ES6 Map with regex keys
body: <p>Is there a more efficient way to reproduce the following code, which involves retrieving a capture group match from a map with keys composed of regular expression objects and values composed of functions accepting the results of matching a key against the regex?</p>
  
  <pre><code>function getFromRegexKeys(key, map) {
    for (let [re, val] of map.entries()) {
      if (re.test(key)) {
        return val(key.match(re));
      }
    }
  }
  
  const map = new Map([
    [/^foo\/(.+)$/, matchResults =&gt; matchResults[1]],
    [/^bar\/(.+)\/(.+)\/(.+)$/, matchResults =&gt; matchResults[2]],
  ]);
  
  getFromRegexKeys('foo/', map); // === undefined
  getFromRegexKeys('foo/quuz', map); // === 'quuz'
  getFromRegexKeys('bar/baz/qux/quz', map); // === 'qux'
  </code></pre>