Empty String Subpattern
<?php
preg_match('/(a)(b)?(c)?/', 'a', $matches);
var_dump($matches);
preg_match('/(a)(b)?(c)?/', 'a', $matches, PREG_UNMATCHED_AS_NULL);
var_dump($matches);
When a subpattern in a regex is not used, PHP reports it by default as an empty string. The entry in the result array is filled, and that empty string may be confused with an actual result. So, you might have to use the PREG_UNMATCHED_AS_NULL flag to make that clear.
See Also
PHP Features
Last updated: 09 November 2026