re = /<iframe[^>]+class=['"][^'"]*?media-element[^>]*?>[\S\s]*?<\/iframe>/i
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>
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html