简体   繁体   English

这个 PHP 表达式有什么问题?

[英]What is wrong with this PHP expression?

Can someone explain to me why the following returns empty arrays?有人可以向我解释为什么以下返回空的 arrays 吗?

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

You've written \d when it should be \d+ :你已经写了\d当它应该是\d+

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

Although it doesn't seem to matter in your case, I'd also escape the braces, as they are special characters.尽管在您的情况下似乎无关紧要,但我也会避开大括号,因为它们是特殊字符。

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

\d should be \d+ for one \d 应该是 \d+ 一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM