I have the following string
$string = "5A3BB0020221209DES.ACT";
And running the following Regex
preg_match_all('/(00)|(?<!^)(?<date>2\d{7}|\d{2}\.\d{2}\.\d{2}|\d{8}|\d{6})/', $string, $m);
When I dump the output of $m['date'], I get an array like this
array(2) {
[0]=>
string(0) ""
[1]=>
string(8) "20221209"
}
I'm only wanting the second result. If I don't have the match group for (00), or there simply isn't a match for group (00), I don't get this extra blank string. Why are other match groups polluting the date match group results with blank strings? I tried adding more match groups, and it added more blank strings to the results of date, for all the match groups that found matches. I could set my code to ignore all the extra blank matches, but this seems like it should be unnecessary. In the preg_match_all docs, I see this exact same behavior in the examples, but I didn't see any explanation as to why or how to get rid of it.