title: Matching iframe src on index 1 in javascript
body: <p>I need to match the url of an iframe src in the index 1. I am using this matchAll function to match multiple occurrences.</p>
  
  <pre><code>if (typeof RegExp.prototype.matchAll !== "function") {
      RegExp.prototype.matchAll = function(v) {
          var tmp     = ""+ this, // So this.toString
              src     = tmp.lastIndexOf("/"),
              pattern = tmp.substring(1, src),
              flags   = tmp.substring(src + 1, tmp.length);
  
          // Never forget "g", that prepends infinite loops for "while"
          if (flags.indexOf("g") == -1) {
              flags += "g";
          }
  
          var re = new RegExp(pattern, flags);
          var ms = [], m;
          while (m = re.exec(v)) {
              ms.push(m);
          }
          return ms;
      };
  }
  </code></pre>
  
  <p>Using this test code: </p>
  
  <pre><code>str = '&lt;iframe width="560" height="315" src="https://www.youtube.com/embed/8L-6Hw7CZLQ" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;';
  var pattern = /\[embed\](.*?)\[\/embed\]|&lt;iframe.*?src="(.*?)".*?&lt;\/iframe&gt;/;
  var matches = pattern.matchAll(str);
  console.log(matches);
  </code></pre>
  
  <p>I do get the src, but on index 2, and I need it on index 1, because the pattern actually matches other things that uses the index 1 as the "url" so I rather match all the urls on that index instead of modifying the entire code.</p>
  
  <p>Whats the correct pattern to get the src url on index 1 for any iframe?</p>