【问题标题】:What is wrong with this PHP expression?这个 PHP 表达式有什么问题?
【发布时间】:2009-03-23 18:51:51
【问题描述】:

有人可以向我解释为什么以下返回空数组吗?

$reg = "/(\[{(false|true)};{.+};{\d}\])+/";
preg_match_all($reg,"[{false};{abcde};{10}][{true};{fghij};{10}]",$matches);
print_r($matches);

【问题讨论】:

    标签: php regex preg-match-all


    【解决方案1】:

    你写的\d应该是\d+

    $reg = "/(\[{(false|true)};{.+};{\d+}\])+/";
    preg_match_all($reg,"[{false};{abcde};{10}][{true};{fghij};{10}]",$matches);
    print_r($matches);
    

    尽管在您的情况下似乎无关紧要,但我也会转义大括号,因为它们是特殊字符。

    $reg = "/(\[\{(false|true)\};\{.+\};\{\d+\}\])+/";
    

    【讨论】:

      【解决方案2】:

      \d 应该是 \d+ 一个

      【讨论】:

        猜你喜欢
        • 2010-09-08
        • 1970-01-01
        • 2021-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多