preg_match两个html标签的结尾

I try to preg_match the end of two html tags

<span class="a"> 
   <span>123</span> 
   <span>456</span></span>
<span class="b">
    <span>789</span>
....

I want to get the content of class a (123 456) and try this pattern

preg_match('#<span\sclass="a">(.*?)</span></span>#')

but I just get the first span (123).

How can I end the pattern in </span></span>

<span class="a">([\W\w]*?)<\/span><\/span>

The dot . only looks for non-newline characters, which means it would never get past the first line (in theory).