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);

preferences:
45.89 ms | 1004 KiB | 5 Q