3v4l.org

run code in 500+ PHP versions simultaneously
<?php $regex = '/(foo)?(bar)?(baz)?/'; $regex = preg_replace('~.[a-z\s]*$~i', '|(?<phpstanNamedCaptureGroupLast>)$0', $regex); var_dump(preg_match($regex, '', $matches, PREG_UNMATCHED_AS_NULL)); var_dump($matches); var_dump(preg_match($regex, '', $matches)); var_dump($matches);
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
int(1) array(6) { [0]=> string(0) "" [1]=> NULL [2]=> NULL [3]=> NULL ["phpstanNamedCaptureGroupLast"]=> NULL [4]=> NULL } int(1) array(1) { [0]=> string(0) "" }

preferences:
60.15 ms | 996 KiB | 4 Q