php正则表达式匹配html标签
用php正则表达式找出div标签,div允许多层嵌套,比如在以下文本中找出class为quizPutTag的div?
<html> <head></head> <body> <div class="quizPutTag"> <span dealflag="1" class="MathJye" mathtag="math" style="whiteSpace:nowrap;wordSpacing:normal;wordWrap:normal"> <table cellspacing="-1" cellpadding="-1"> <tbody> <tr> <td style="font-size: 0px"> <div hassize="7"> <div> </div> <div> </div> </div> </td> <td style="padding:0;padding-left: 2px; border-top: black 1px solid;line-height:normal;padding-top:1px"> <table cellspacing="0" cellpadding="0"> <tbody> <tr> <td> v </td> <td style="line-height: normal; padding-left: 1px; font-size: 90%"> <div mathtag="msubsup_sup" hassize="-1"> 2 </div> <div mathtag="msubsup_sub"> 0 </div> </td> </tr> </tbody> </table> + <table cellpadding="-1" cellspacing="-1" style="margin-right:1px"> <tbody> <tr> <td style="border-bottom:1px solid black;padding-bottom:1px;font-size:90%"> <span> <span> <span> <span> 8? </span> <span style="vertical-align:super;font-size:90%"> 2 </span> </span> r </span> <span style="vertical-align:super;font-size:90%" dealflag="1"> 3 </span> </span> h </td> </tr> <tr> <td style="padding-top:1px;font-size:90%"> <span> <span> <table cellspacing="0" cellpadding="0"> <tbody> <tr> <td> <span> <span> T </span> <span style="vertical-align:super;font-size:90%"> 2 </span> </span> r </td> <td style="line-height: normal; padding-left: 1px; font-size: 90%"> <div mathtag="msubsup_sup" hassize="-1" dealflag="1"> 2 </div> <div mathtag="msubsup_sub"> 0 </div> </td> </tr> </tbody> </table> </span> <span style="vertical-align:super;font-size:90%" dealflag="1"> </span> </span> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </span> </div> <!--EA--> <div class="sanwser"> <span dealflag="1" class="MathJye" mathtag="math" style="whiteSpace:nowrap;wordSpacing:normal;wordWrap:normal"> <table cellspacing="-1" cellpadding="-1"> <tbody> <tr> <td style="font-size: 0px"> <div hassize="7"> <div> </div> </div> </td> <td style="padding:0;padding-left: 2px; border-top: black 1px solid;line-height:normal;padding-top:1px"> <table cellspacing="0" cellpadding="0"> <tbody> <tr> <td> v </td> <td style="line-height: normal; padding-left: 1px; font-size: 90%"> <div mathtag="msubsup_sup" hassize="-1"> 2 </div> <div mathtag="msubsup_sub"> 0 </div> </td> </tr> </tbody> </table> + <table cellpadding="-1" cellspacing="-1" style="margin-right:1px"> <tbody> <tr> <td style="border-bottom:1px solid black;padding-bottom:1px;font-size:90%"> <span> <span> <span> <span> 8? </span> <span style="vertical-align:super;font-size:90%"> 2 </span> </span> r </span> <span> 3 </span> </span> h </td> </tr> <tr> <td> <span> <span> <table cellspacing="0" cellpadding="0"> <tbody> <tr> <td> <span> <span> T </span> <span> 2 </span> </span> r </td> <td style="line-height: normal; padding-left: 1px; font-size: 90%"> <div mathtag="msubsup_sup" hassize="-1" dealflag="1"> 2 </div> <div mathtag="msubsup_sub"> 0 </div> </td> </tr> </tbody> </table> </span> <span style="vertical-align:super;font-size:90%" dealflag="1"> </span> </span> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </span> </div> </body> </html>
结果如下图中红色文字
表达式为
<div class="quizPutTag">([\s\S]*?(<div[^>]*>((?1)|[\s\S])*<\/div>)*[\s\S]*?)*<\/div>