Sounds like a good job for preg_match or preg_replace.
This probably won't work first go but it gives you a start.
echo preg_replace( "/.+?<[aA].*?href=(.*?)\.jpg.*/","\\1.jpg",$string );
If you have ' or " around it just do a str_replace after the preg_replace
HalfaBee