MySQL's SUBSTRING_INDEX()
function is pretty much tailor made for what you're trying to do:
> select substring_index( 'foo.png', '.', -1 );
+---------------------------------------+
| substring_index( 'foo.png', '.', -1 ) |
+---------------------------------------+
| png |
+---------------------------------------+
1 row in set (0.01 sec)
> select substring_index( 'foo.bar.jpg', '.', -1 );
+-------------------------------------------+
| substring_index( 'foo.bar.jpg', '.', -1 ) |
+-------------------------------------------+
| jpg |
+-------------------------------------------+
1 row in set (0.00 sec)