A Missing Subpattern
<?php
preg_match('/(a)(b)*(c)/', 'ac', $matches);
var_dump($matches);
preg_match('/(a)(b)*(c)/', 'ac', $matches, PREG_UNMATCHED_AS_NULL);
var_dump($matches);
When the final subpattern(s) are not found, PHP does not create their corresponding entry. Hence, the resulting array may have only two entries, while there are actually four subpatterns. To avoid this surprise, use the PREG_UNMATCHED_AS_NULL flag to make them always created, with NULL value when not found.
See Also
PHP Features
Last updated: 09 November 2026