What is wrong with this PHP expression?
-
21-08-2019 - |
Question
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);
Solution
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+\}\])+/";
OTHER TIPS
\d should be \d+ for one
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow