Disclaimer: I do not need another better regular expression without reset groups. I need to understand why the output is different for PHP 5
and PHP 7
.
Problem: I tried to use a branch reset group to match a string using PHP
which consists of groups of digits separated by different separators.
$string = '12-34-56-78';
$pattern = '/^\d{2}(?|(---)|(-)|(\.)|(\:))\d{2}\1\d{2}\1\d{2}$/';
$matches = preg_match($pattern, $string) === 1;
var_dump($matches);
Unfortunately it works only for PHP < 7
. I also checked the version of the libpcre
and it's not the source of the problem. The same version of the libpcre
returns different results for different PHP
versions.
I wasn't able to find any references to what and why changed in PHP 7
.
Question: why the output different for PHP 5
and PHP 7
? Is it an expected behavior for PHP 7
?
Update: seems to be a bug.
It was a bug and it was fixed.