3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $expr = <<<REGEX / \b # word boundary [a-z]{2,3} # 2 or 3 letters \s* # optional spaces [0-9]{2,3} # 2 or 3 digits (?: # start optional non-capturing group \s* # optional spaces [a-z] # single letter )? # end optional non-capturing group \b # word boundary /ix REGEX; $strs = array( 'Honda : CRF 2005 honda crf 50 dirt bike pit bike', 'Honda : XR 2001 honda xr 400 r', 'Honda : CRF 2005 honda crf50 dirt bike pit bike', 'Honda : XR 2001 honda xr400r', ); foreach ($strs as $str) { if (preg_match($expr, $str, $matches)) { var_dump($matches[0]); } }
based on pYfit
Output for 4.3.0 - 7.1.0
string(6) "crf 50" string(8) "xr 400 r" string(5) "crf50" string(6) "xr400r"