$re = '/<slb:ReturnCode>(?<ReturnCode>.*?)<\/slb:ReturnCode>.*?(?:<slb:Message>(?<FailureMessage>.*?)<\/slb:Message>|<slb:SearchResultsCount>(?<Count>\d)<\/slb:SearchResultsCount>).*?<slb:CustomerId>(?<CustomerID>.*?)<\/slb:CustomerId>.*?<slb:AccountId>(?<AccoundId>.*?)<\/slb:AccountId>.*?<slb:LocationId>(?<LocationId>.*?)<\/slb:LocationId>/m';
$str = '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:slb="http://www.csgsystems.com/slbos"><soapenv:Header /><soapenv:Body><slb:RetrieveAccountResponse><slb:head><slb:Client>ElnkFive9IOT</slb:Client><slb:RoutingArea>8024</slb:RoutingArea><slb:Region>QAHA</slb:Region><slb:Source>IVR</slb:Source><slb:Destination>CCS</slb:Destination><slb:Version>17.4</slb:Version><slb:TransactionId>72ccf13c-1534-11eb-8111-005056b21df3</slb:TransactionId><slb:ServerId>OTPRESLBWCF04</slb:ServerId></slb:head><slb:Response><slb:ReturnCode>0000</slb:ReturnCode></slb:Response><slb:SearchResultsCount>1</slb:SearchResultsCount><slb:SearchResults><slb:Region>QAHA</slb:Region><slb:Business><slb:BusinessUnit>802440000360</slb:BusinessUnit></slb:Business><slb:Customer><slb:CustomerId>1101521209580</slb:CustomerId></slb:Customer><slb:Account><slb:AccountId>8024400360071309</slb:AccountId><slb:Classification> </slb:Classification><slb:Type>RES</slb:Type><slb:ConnectStatus> </slb:ConnectStatus><slb:Name><slb:Salutation>U</slb:Salutation><slb:First>TEST2</slb:First><slb:Last>FIVE9SWAP</slb:Last></slb:Name><slb:Phone><slb:Home>9026852256</slb:Home></slb:Phone><slb:LineOfBusinessCount>5</slb:LineOfBusinessCount><slb:LineOfBusiness><slb:Type>C</slb:Type><slb:TypeDescription>VIDEO </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>I</slb:Type><slb:TypeDescription>HSD </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>T</slb:Type><slb:TypeDescription>TELEPHONY</slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>Y</slb:Type><slb:TypeDescription>WIRELESS </slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>Z</slb:Type><slb:TypeDescription>SECURITY </slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:Balance><slb:Current>155.14</slb:Current><slb:Projected>155.14</slb:Projected><slb:Statement>155.14</slb:Statement><slb:Highest>155.00</slb:Highest></slb:Balance><slb:PPVCreditLimit>250.00</slb:PPVCreditLimit><slb:Payment><slb:SubType> </slb:SubType><slb:SubTypeStatus> </slb:SubTypeStatus><slb:History>0 </slb:History><slb:LastDate>0001-01-01</slb:LastDate><slb:LastAmount>0.00</slb:LastAmount><slb:FutureDated>N</slb:FutureDated></slb:Payment><slb:BillTo><slb:Name><slb:Salutation>U</slb:Salutation><slb:First>TEST2</slb:First><slb:Last>FIVE9SWAP</slb:Last></slb:Name><slb:StatementNameFormat>2</slb:StatementNameFormat><slb:Address><slb:Line1>123 SEAN ST</slb:Line1><slb:City>HALIFAX</slb:City><slb:State>NS</slb:State><slb:PostalCode>B3M0A2</slb:PostalCode><slb:ForceIndicator>1</slb:ForceIndicator><slb:Country>CAN</slb:Country></slb:Address><slb:AddressInheritanceIndicator>Y</slb:AddressInheritanceIndicator></slb:BillTo><slb:Billing><slb:CycleDay>22</slb:CycleDay><slb:FromDate>2020-10-22</slb:FromDate><slb:ThruDate>2020-11-21</slb:ThruDate><slb:Frequency>01</slb:Frequency><slb:TaxGroup>99</slb:TaxGroup><slb:DemandStatement>N</slb:DemandStatement><slb:StatementHold>N</slb:StatementHold><slb:EBPP>N</slb:EBPP><slb:Electronic>N</slb:Electronic><slb:ElectronicOutsourced>N</slb:ElectronicOutsourced><slb:Hardcopy>Y</slb:Hardcopy></slb:Billing><slb:Identification><slb:TaxIdentifier>XXXXXXXXX</slb:TaxIdentifier><slb:TaxType>X</slb:TaxType><slb:PIN>00000</slb:PIN></slb:Identification><slb:Delinquency><slb:Status> </slb:Status><slb:ChargeOff><slb:Reason slb:Index="1"><slb:Code>00</slb:Code><slb:Description>Misappld Pymnt</slb:Description></slb:Reason><slb:Amount>0.00</slb:Amount></slb:ChargeOff><slb:DunningGroup>030</slb:DunningGroup></slb:Delinquency><slb:MonetaryStatus> </slb:MonetaryStatus><slb:SalesRepresentative>0</slb:SalesRepresentative><slb:ConnectDate>2020-10-22</slb:ConnectDate><slb:LastMonetaryType>S</slb:LastMonetaryType><slb:LastMonetaryDate>2020-10-22</slb:LastMonetaryDate><slb:LastNonMonetaryDate>2020-10-22</slb:LastNonMonetaryDate><slb:AutoPackageIndicator>P</slb:AutoPackageIndicator><slb:RestrictTroubleCall>N</slb:RestrictTroubleCall><slb:RestrictPPV>N</slb:RestrictPPV><slb:CustomField slb:Index="2"><slb:Name>RETIREE ID </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="3"><slb:Name>COM TEST1 </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="4"><slb:Name>COMM CLASS </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="5"><slb:Name>ARMSTRONG ACCT</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="6"><slb:Name>NO COLLECTIONS</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="7"><slb:Name>COLLECT LETTER</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="8"><slb:Name>CONTRACT (ER) </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="9"><slb:Name>BWOS # </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="10"><slb:Name>BANKRUPTCY </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="11"><slb:Name>COLLECTIONS </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="12"><slb:Name>PAY ARRANGEMEN</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="13"><slb:Name>MIND ACCT # </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="14"><slb:Name>AM COLLECTOR #</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="15"><slb:Name>LOW USAGE </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="16"><slb:Name>LEGACY ACCT# </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:Audit><slb:Creation><slb:Date>2020-10-22</slb:Date></slb:Creation></slb:Audit></slb:Account><slb:Location><slb:LocationId>11322010200009</slb:LocationId><slb:Type>AA</slb:Type><slb:TypeDescription>Residence</slb:TypeDescription><slb:Address><slb:Line1>123 SEAN ST</slb:Line1><slb:City>HALIFAX</slb:City><slb:State>NS</slb:State><slb:PostalCode>113220102</slb:PostalCode></slb:Address><slb:LineOfBusinessCount>4</slb:LineOfBusinessCount><slb:LineOfBusiness><slb:Type>C</slb:Type><slb:TypeDescription>VIDEO </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>I</slb:Type><slb:TypeDescription>HSD </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>T</slb:Type><slb:TypeDescription>VOICE </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>Z</slb:Type><slb:TypeDescription>SECURITY </slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:Drop><slb:Tag slb:Index="1"><slb:Identifier>SEAN</slb:Identifier></slb:Tag></slb:Drop></slb:Location></slb:SearchResults></slb:RetrieveAccountResponse></soapenv:Body></soapenv:Envelope>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php