There are several ways.One of it:
1st u do a explode for the '-':
$ar1 = explode('-',$string);
Then u will have the last element (eg 12.jpg) in:
$last_element = $ar1[ count($ar1) - 1];
Then u do another explode for the '.':
$ar2 = explode('.',$last_element);
And you will have what u need in $ar2[ count($ar2) - 1]