3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php foreach ( array( array('/\\d+/', '$0'), array('/\\d+/', '$01'), array('/\\d+/', '$001'), array('/\\d+/', '${0}1'), array('/(\\d+)/', '$0'), array('/(\\d+)/', '$01'), array('/(\\d+)/', '{$0}1'), array('/(\\d+)/', '$1'), array('/(\\d+)/', '$12'), array('/(\\d+)/', '$012'), array('/(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(\\d+)/', '$12'), array('/(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(\\d+)/', '$123'), ) as $list ) { list ($re, $replace) = $list; echo "$re '$replace' => '", preg_replace($re, $replace, "42"), "'\n"; }
based on YGKMj
Output for 4.3.0 - 5.6.30, hhvm-3.10.1 - 3.17.3, 7.0.0 - 7.3.0alpha1
/\d+/ '$0' => '42' /\d+/ '$01' => '' /\d+/ '$001' => '421' /\d+/ '${0}1' => '421' /(\d+)/ '$0' => '42' /(\d+)/ '$01' => '42' /(\d+)/ '{$0}1' => '{42}1' /(\d+)/ '$1' => '42' /(\d+)/ '$12' => '' /(\d+)/ '$012' => '422' /(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(\d+)/ '$12' => '42' /(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(^)(\d+)/ '$123' => '423'