简体   繁体   中英

What is wrong with this PHP expression?

Can someone explain to me why the following returns empty 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+ :

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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