3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $subject = "3rd from last"; preg_match('~(?:(?P<index>[0-9]+)rd|st) from (?P<position>(last|end|start|beginning)+)~', $subject, $matches); var_dump($matches);
Output for 4.3.3 - 7.1.0
array(6) { [0]=> string(13) "3rd from last" ["index"]=> string(1) "3" [1]=> string(1) "3" ["position"]=> string(4) "last" [2]=> string(4) "last" [3]=> string(4) "last" }
Output for 4.3.0 - 4.3.2
array(4) { [0]=> string(13) "3rd from last" [1]=> string(1) "3" [2]=> string(4) "last" [3]=> string(4) "last" }