re = /<div class="row">[\n\s]*<div class="col-md-6">[^<]*<\/div>[ \n\s]*<\/div>/
str = '<div class="container header">
<div class="row">
<div class="col-md-6">This is the target text</div>
</div>
</div><span /><a href...></a>Whatever
<div class="container header">
<div class="row">
<div class="col-md-6">This is the target text</div>
</div>
</div>'
# 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