Rewrite rule please help me

Hello

I have a domain where i need a redirection as described below :

i.e

mydomain.com/t-ABC-048796/sample.jpg

must redirect to

mydomain.com/jjj/top/8796/sample.jpg

As you can see from the source URL (mydomain.com/t-ABC-048796/sample.jpg) i need the last four characters from the directory name

t-ABC-048796 i.e 8796 . Then it should redirect tocorresponding file under the directory named 8796 (last four characters of directory named t-ABC-048796 ) under mydomain.com/jjj/top/ i.e to the destination URL must be mydomain.com/jjj/top/8796/sample.jpg