I have a string of HTML where some inherited div present and I need to extract only the top level div, for example-
$html= '<div class="test">
            <div>
                <div>Some text 1</div> 
                <div>Image content 2</div>
            </div>
            <div>
                <div>Some text 2</div> 
                <div>Image content 2</div>
            </div>
            ....
        </div>';
$regex ='/<div\sclass=[\"\']test[\"\']>.*?<\/div>/is';
preg_match($regex, $html, $matches);    
But the real problem is the result shows me only the first Some text 1</div>, Please help me to figure out where I made the mistakes?
I need to grab the entire class test 'div' as a result matches.
<div>
    <div>Some text 1</div> 
    <div>Image content 2</div>
</div>
<div>
     <div>Some text 2</div> 
     <div>Image content 2</div>
</div>
 
    