In perl regex we can extract the matched variables, ex below.
# extract hours, minutes, seconds $time =~ /(\\d\\d):(\\d\\d):(\\d\\d)/; # match hh:mm
Try using the named subpattern syntax of preg_match:
\w+): (?\d+)/', $str, $matches); // Before PHP 5.2.2, use this: // preg_match('/(?P\w+): (?P\d+)/', $str, $matches); print_r($matches); ?>
Output:
Array ( [0] => foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008 )