const regex = /<iframe[^>]+class=['"][^'"]*?media-element[^>]*?>[\S\s]*?<\/iframe>/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<iframe[^>]+class=[\'"][^\'"]*?media-element[^>]*?>[\\S\\s]*?<\\\/iframe>', 'gi')
const str = `<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360" width="48"></iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360" width="48">
</iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360" src="https://www.youtube.com/embed/_OBlgSz8sSM?feature=oembed" width="480">
</iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360"></iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360"></iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360"></iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360"></iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360"></iframe>
<iframe allowfullscreen="" class="media-element file-default" data-fid="15" data-media-element="1" frameborder="0" height="360" width="48"></iframe>
<iframe class="media-element">
</iframe>
<iframe class="media-element">
</iframe>
<iframe class="media-element"></iframe>
<iframe class="media-element"></iframe>
<iframe class="media-element"></iframe>
<iframe class="media-element"></iframe>
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions