首页 > 代码库 > 常用正则

常用正则

1、匹配嵌套DIV

$str = ‘<div id="test">‘.            ‘<div>1‘.                                ‘<div>1-1‘.                                        ‘<div>1-1-1‘.                                            ‘</div>‘.                ‘</div>‘.            ‘</div>‘.            ‘<div>2</div>‘.            ‘<span>3</span>‘.            ‘<div>4</div>‘.        ‘</div>‘;            $regex = "/<div.*?id=\"test\".*?>(<.*?>.*?<\/.*?>){0,10}<\/div>/is";preg_match ( $regex, $str, $m );  print_r($m);

 

常用正则