phpQuery使用正则表达式返回错误的结果

时间:2014-07-20 09:23:42

标签: regex phpquery

    $html = '<html>
                <body>
                    <div id="dupe_1">1
                        <div class="dupe_1.1">1.1</div>
                        <div id="dupe_1.2">1.2</div>
                    </div>
                    <div id="dupe_2">2
                        <div class="dupe_2.1">2.1</div>
                        <div id="dupe_2.2">2.2</div>
                        <div>extra</div>
                    </div>
                </body>
            </html>';
    $html = phpQuery::newDocumentHTML($html);
    $node = pq('div:regex(id,^dupe_\d+$)',$html);
    echo count($node);

这将返回7,即所有div。它应该只返回2个div(dupe_1和dupe_2)

1 个答案:

答案 0 :(得分:0)

我会避免做那样的事情,你应该能够得到那些用css:

[id*=dupe_]:not([id*="."])