re = /<Equipment>[\s\S]+?<\/Equipment>/m
str = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p237:getNewSampleSerialNumsOutput xmlns:p237="http://www.cat.com/sos/2008/07/15/EquipmentService/">
<Equipment>
<p463:serialNumber xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15">ZBD11674</p463:serialNumber>
<p463:make xsi:nil="true" xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15"/>
</Equipment>
<Equipment>
<p463:serialNumber xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15">ZBF11179</p463:serialNumber>
<p463:make xsi:nil="true" xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15"/>
</Equipment>
<Equipment>
<p463:serialNumber xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15">ZBF11507</p463:serialNumber>
<p463:make xsi:nil="true" xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15"/>
</Equipment>
</p237:getNewSampleSerialNumsOutput>
</soapenv:Body>
</soapenv:Envelope>'
# 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