views:

95

answers:

2

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);
+2  A: 

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+\}\])+/";
Greg
+2  A: 

\d should be \d+ for one

cobbal